Using break Command In Linux- Examples

break command in Linux is a way allowing users to terminate any active loop such as while loop or until loop. While using this command, it takes a parameter [n] which stands for number of nested loops to break, where the default value of n is 1. Continue command later can be used to continue the terminated loop one again.

Also Read:   Using bison Command In Linux (Examples)

Syntax to use break command in Linux

break [n]

Options to use with break command

n: The number of nested loops to break, where the default n=1.

Sample instances of break command

1: Terminating a loop

for I in ‘seq 11 20’
> do
> if (( $i==15 ))
> then
> break
> fi
> echo $i
> done
Output:
11
12
13
14

2: Using break command in until loop

i=11
until (( $i==19 ))
> do
> if (( $i==16 ))
> then
> break
> fi
> echo $i
> done
Output:

11
12
13
14

3: Showing help information

break -help

break command in Linux

Nishant

Nishant Verma is a senior web developer who love to share his knowledge about Linux, SysAdmin, and more other web handlers. Currently, he loves to write as content contributor for ServoNode.