break command (exits from a loop)
- Organization of this page
Format
break [n]
Description
This command exits from a loop that occurs in a for statement, while statement, or other looping control structure. If this command is executed while processing is not in a loop, it outputs a message and terminates normally.
Argument
- n
-
Specifies the number of nested loops from which the command is to exit. Specify 1 or a greater integer.
When n is specified, the command exits out of n loops. When n is omitted, the command exits to the first enclosing loop.
If the command is executed with a value for n that exceeds the current number of nested looping structures, it continues exiting through the outermost loop, and then outputs a message and terminates normally.
Return codes
Return code |
Meaning |
---|---|
0 |
Normal termination |
1 |
Error termination
|
Notes
-
If the value of n is 0 or smaller or exceeds 2,147,483,647, overflow will occur. The overflow digits are ignored and processing continues. We recommend that you specify a value in the range from 1 to 2,147,483,647.
-
If the command syntax of this special built-in command is invalid, it exits the shell that is executing the command.
Usage example
-
Exit to the second enclosing loop.
break 2