LDP/LDP/guide/docbook/abs-guide/continue-nlevel.sh

31 lines
799 B
Bash
Raw Normal View History

2001-07-10 14:25:50 +00:00
#!/bin/bash
# The "continue N" command, continuing at the Nth level loop.
for outer in I II III IV V # outer loop
do
echo; echo -n "Group $outer: "
2005-05-08 20:09:31 +00:00
# --------------------------------------------------------------------
2001-07-10 14:25:50 +00:00
for inner in 1 2 3 4 5 6 7 8 9 10 # inner loop
do
if [[ "$inner" -eq 7 && "$outer" = "III" ]]
2001-07-10 14:25:50 +00:00
then
continue 2 # Continue at loop on 2nd level, that is "outer loop".
2001-09-04 13:27:31 +00:00
# Replace above line with a simple "continue"
# to see normal loop behavior.
2001-07-10 14:25:50 +00:00
fi
2008-11-23 22:43:47 +00:00
echo -n "$inner " # 7 8 9 10 will not echo on "Group III."
2001-07-10 14:25:50 +00:00
done
2005-05-08 20:09:31 +00:00
# --------------------------------------------------------------------
2001-07-10 14:25:50 +00:00
done
echo; echo
2002-04-01 16:04:17 +00:00
# Exercise:
2001-07-10 14:25:50 +00:00
# Come up with a meaningful use for "continue N" in a script.
exit 0