break: Exit from a loop

Exit from a for, while, until,
or select loop
SYNTAX
break [n]
If n is supplied, the nth enclosing loop is exited. n
must be greater than or equal to 1.

The return status is zero unless n is not greater than or equal to
1.

Example
for myloop in 1 2 3 4 5
do
echo -n "$myloop"
if [ "$myloop" -eq 3 ]
then
break # This line will break out of the loop
fi
done
break is a POSIX `special? builtin
"Don?t worry about the world coming to an end today. It?s already tomorrow
in Australia." - Charles
Schultz
Related:

for - Expand words, and execute commands
select - Accept keyboard input
until - Execute commands (until error)
while - Execute commands
continue - Resume the next iteration of a loop
Equivalent Windows command: GOTO :eof - Jump to end of file

Tags
Comments
Write the first comment
Leave a trace
Name *
Email *
Website
Anti SPAM * Code (3 + 2) =
Leave me a comment *
 
All comments are subject to editorial review
Post being viewed right now
Item date: 09.03.2009
Views: 519
Item date: 26.09.2009
Views: 1667
Item date: 05.02.2009
Views: 900
Item date: 01.06.2008
Views: 2149
Item date: 09.03.2009
Views: 518
Item date: 12.04.2009
Views: 1729
Item date: 22.08.2009
Views: 1418
Item date: 26.09.2009
Views: 411
Item date: 09.03.2009
Views: 865