while loop

The while loop, in comparison to the do loop, has its conditional expression at the beginning, and therefore, the statement will only be executed as long as the conditional expression returns $true:

# simple syntax of a while-loop
# while (<condition>)
# {
# <statement list>
# }

Take a look at the following example, which returns the same values as the do loop examples:

# simple example for while-loop
$a = 0
while ($a -lt 5)
{
$a++
$a
}
# 1, 2, 3, 4, 5
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset