break

Official Description

Exits from the enclosing for, while, until, or select loop, if any.

Syntax

break [n]

Options

None

Oddities

You can supply a number (n) indicating how many levels of nesting to break out of.

Might not have its own man page. Look in ksh man page for information.

Example

$ cat buzz1
#! /bin/ksh
integer x=17
while :                      # Potentially infinite loop
do
x=x+1
if (( x>20 ))
then
         break               # Break out when x>20
fi
done
print $x
$
$ buzz1
21
$
$
$ cat buzz2
#! /bin/ksh
integer x=17
integer y=0
for (( y=0; y<5; y++ ))      # Outer loop
do
        while :              # Inner loop
        do
        x=x+1
        if (( x>20 ))
        then
                 break 2     # Break out of both
        fi
        done
done
print $x
print $y
$
$ buzz2
21
0
$
				

Get Korn Shell Programming by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.