next up previous contents index
Next: I/O Up: Control Structures Previous: Foreach   Contents   Index


While

The control structure 'while' will do the instructions inside its { } as long as the boolean expression in the ( ) is true. In this case $count starts at 0 (the default value of a number). Since 0 < 10, 1 is added to it ($count += 1) and the result is printed. The next time around $count is 1. Since 1 < 10, 1 is added to it and the result is printed. When $count is 10, the boolean expression is false, the loop is done, and the program moves on to the statements after the }.

    while ($count <10) {
        $count += 1 ; 
        print "count = $count\n" ;
    }



Tom Hunt 2002-06-09