Concept
Why should a while-loop condition not end with a semicolon in PHP?
ComputerScienceOne / While Loops
"The continuation condition does not contain a semicolon since it is not an executable statement. Just as with an if-statement, if we had placed a semicolon it would have led to unintended results. Consider the following:\n\n1 while($i <= 10); {\n\n2 //perform some action\n\n3 $i++; //iteration\n\n4 }\n\nA similar problem occurs. The while keyword and continuation condition bind to the next executable statement or code block. As a consequence of the semicolon, the executable statement that gets bound to the while loop is empty."
Related Ideas
- Why should you avoid a semicolon after a while condition?ComputerScienceOne · While Loops
- Why should you avoid a semicolon after a while-loop condition?ComputerScienceOne · While Loops
- What happens when a while loop never increments its counter?ComputerScienceOne · For Loops
- How does a do-while loop differ from a while loop in PHP?ComputerScienceOne · Do-While Loops
- How does a do-while loop differ from a while loop in PHP?ComputerScienceOne · Foreach Loops
- Why does an extra semicolon make the conditional statement ineffective?ComputerScienceOne · Computing a Logarithm
- How do if, if-else, and if-else-if statements work in PHP?ComputerScienceOne · If, If-Else, If-Else-If Statements
- How are strings, statements, and code blocks written in PHP?ComputerScienceOne · Basic Syntax Rules