3 ms·
While loops are restricted gotos with syntactic sugar.
by jcsalterego 17y ago
While loops are restricted gotos with syntactic sugar.
- ComputerGuru 17y agoNow that I come to think of it, it actually doesn't matter for PHP. While loops limit the scope of variables inside the loop. For C++, that means a variable declared inside cannot be used outside - logical, and OOP. But PHP has no concept of privacy or scope, even its "rules" may be broken (though not guaranteed to always work) and come out with the right results. Anything will compile, and usually the results are as expected. So if you have a while loop with no concept of scope or local variables, I guess the restrictions are gone. A number of nested loops with breaks; and continues; all over end so long as the concept of limited data scope/access is not present as in PHP are exactly equivalent to goto as it is. I guess a language as, shall we say, 'relaxed' as PHP is well-matched with relaxed keywords like goto.
- pbiggar 17y agoNo, thats not what he means. He means that gotos are unstructured, and you can do anything with them, like jumping into a loop. Although, PHP's gotos don't allow they, and PHP still only admits structured control flow.