Skip to content
Justice Tech School

while, until and break

while repeats while a command succeeds. until repeats until it succeeds.

Example
n=0
while (( n < 5 )); do
  ((n++))
  (( n == 2 )) && continue
  (( n == 4 )) && break
  echo "n=$n"
done
until (( n >= 6 )); do ((n++)); done
echo $n

Result

n=1
n=3
6

Exercise

Opposite of while.

 cond; do :; done

Quiz Test

What does continue do?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.