Bifalgorithm post · Computer science one · While Loops

How are while loops structured and styled in PHP?

How are while loops structured and styled in PHP? (Computer science one · While Loops) — "PHP supports while loops, for loops, and do-while loops using the key…

Ideas in this flowchart

  • PHP supports several types of loops.
  • PHP provides while, for, and do-while loops.
  • The while loop uses the keyword while.
  • The for loop uses the keyword for.
  • The do-while loop uses do together with while.
  • Loop syntax uses specific delimiters.
  • Continuation conditions are enclosed in parentheses.
  • Loop code blocks are enclosed in curly brackets.
  • The coding style specifies how loop blocks are formatted.
  • The opening curly bracket appears on the same line as while and its continuation condition.
  • The inner block is indented consistently.
  • Code Sample 39.1 demonstrates a basic while loop.
  • The loop initializes $i to 1.
  • The loop continues while $i is less than or equal to 10.
  • The loop performs an action inside its code block.
  • The iteration increments $i.
  • The continuation condition has no semicolon because it is not an executable statement.
Feed/

How are while loops structured and styled in PHP?

No cover

Channel

Computer science one

1 page

"PHP supports while loops, for loops, and do-while loops using the keywords while, for, and do (along with another while). Continuation conditions for loops are enclosed in parentheses, (...) and blocks of code associated with the loop are enclosed in curly brackets. Code Sample 39.1 contains an example of a basic while loop in PHP. As with conditional statements, our code style places the opening curly bracket on the same line as the while keyword and continuation condition. The inner block of code is also indented and all lines in the block are indented to the same level. In addition, the continuation condition does not contain a semicolon since it is not an executable statement. What happens is:\n\n1 $i = 1; //Initialization\n\n2 while($i <= 10) { //continuation condition\n\n3 //perform some action\n\n4 $i++; //iteration\n\n5 }\n\nCode Sample 39.1.: While Loop in PHP 527"

Flowchart preview
👍
0
0 comments0 shares

Sign in to view and post comments.