Code Library
Home Submit Free Hosting Link To Us Contacts

Bash Breaking out of loops

Bash Breaking out of loops Bash Bash Breaking out of loops Download (.zip)



#!/bin/bash
# break-levels.sh: Breaking out of loops.

# "break N" breaks out of N level loops.

for outerloop in 1 2 3 4 5
do
echo -n "Group $outerloop: "

for innerloop in 1 2 3 4 5
do
echo -n "$innerloop "

if [ "$innerloop" -eq 3 ]
then
break # Try break 2 to see what happens.
# ("Breaks" out of both inner and outer loops.)
fi
done

echo
done

echo

exit 0






Bash Breaking out of loops