Basic Control Structures in PHP
By Darren W. Hedlund2005-06-20
Notes on embedding code blocks
When writing programs, it is often common to embed conditions, or even other loops, within other loops or conditionals. For example, the following will count from 1 to 5 but display the string "Magic Number!" before it displays the number 3:
<?php $count = 1; while($count <= 5) { if($count == 3) { echo "Magic Number!<br />"; } echo $count."<br />"; $count++; } ?>
This feature is an important part of the language and is used quite frequently; it can be used in any syntax where a code block (distinguished by the { and } symbols) exists.
Tutorial Pages:
» Conditional blocks
» The if statement
» Basic looping
» The while statement
» Infinite loops
» Notes on embedding code blocks
