Control:While
Jump to navigation
Jump to search
Forms
While
while <formula> <command or code block>
This form will conditionally execute the following command or code block. The command or code block must begin on the following line. The command or code block will be executed if the result of the calculation is not equal to zero (0), which means it will be skipped if the result of the calculation is equal to zero (0). After executing the command or code block, execution will return to the while, where the entire process repeats (formula is evaluated, code is either executed or skipped, ad infinitum).
Do-While
do <command or code block> while <formula>
This form is very similar to the first form. The difference is simply that the code will always execute at least once, and the repeat condition is checked afterwards.
Examples
The following two examples both produce the following output:
1 2 3 4 5 6 7 8 9 10
While
delcare Count int 0 while ${Count:Inc}<=10 echo ${Count}
Do-While
declare Count int 1 do { echo ${Count} } while ${Count:Inc}<=10