Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Difference between "while" and "until" in Bash
- While Loop executes the block of code (enclosed in do...done) when the condition is true and keeps executing that till the condition becomes false. Once the condition becomes false, the while loop is terminated.
- Until Loop executes the block of code (enclosed in do...done) when the condition is false and keep executing that till the condition becomes true. Once the condition becomes true, the until loop is terminated.
- # loops to print 1 2 3 4 5 6 7 8 9 10
- #*****************while**************************
- i=1
- while [ $i -le 10 ]
- do
- echo $i
- i=`expr $i + 1`
- done
- # ******************for loop**********************
- for i in 1 2 3 4 5 6 7 8 9 10
- do
- echo $i
- done
- # ******************until**********************
- i=1
- until [ $i -gt 10 ]
- do
- echo $i
- i=`expr $i + 1`
- done
- Outupt of all three loops
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
Add Comment
Please, Sign In to add comment