break

Exit from a for, while, until or select loop.

Syntax
 break [n]

If n is specified, break n levels.

n must be >= 1. If n is greater than the number of enclosing loops, all enclosing loops are exited.

The return value is 0 unless the shell is not executing a loop when break is executed.

This is a BASH shell builtin, to display your local syntax from the bash prompt type: help break

Examples

Break out of a loop when the count reaches 3:

for i in 1 2 3 4 5
do echo -n "Hello World${i} "
 if [ "$i" -eq 3 ] 
 then 
 break # This line will break out of the loop
 fi
done

"Don’t worry about the world coming to an end today. It’s already tomorrow in Australia" ~ Charles Schultz

Related macOS commands

Local man page: break - Command line help page on your local machine.
continue - Resume the next iteration of a while or foreach loop.
for - Loop, expand words, and execute commands.
while - Execute commands.

(追記) (追記ここまで)
Copyright © 1999-2026 SS64.com
Some rights reserved

AltStyle によって変換されたページ (->オリジナル) /