13,420
edits
Changes
→Additional Loop Statements
[[Image:while-loop.png|thumb|right|170px|Example of how a '''while''' loop works.]]'''Using the while Loop Statement'''
The '''while''' loop is useful to loop based on the result from a test condition or command result. This type of loop is very useful for '''error-checking'''.<br><br>''How it Works:''<br>The condition/expression is evaluated, and if the condition/expression is true,<br>the code within … the block is executed.
This repeats until the condition/expression becomes FALSE.<br>Reference: https://en.wikipedia.org/wiki/While_loop
''Example:''
<span style="font-family:courier">answer=10<br>read –p “pick a number between 1 and 10: “ guess<br>while test $guess –eq 10<br>do read –p “Try again: “ guess<br>done<br>echo “You are correct”</span><br><br>