Using continue Command In Linux- Examples

continue command in Linux is basically used to skip current iteration in for, while and until loop. Alike break command, it takes only one parameter [n], where n is stands for nth number for enclosing group. Means, if n is defined, the continue command will continue from nth enclosing loop.

Syntax to use continue command in Linux

continue

or

continue [n]

Options available to use with continue command

n: If n is specified, the nth enclosing loop is exited. The value of n must be greater than or equal to 1.
–help: Displays help information and exits.

Examples of continue command

1: Using continue command in ‘for’ loop

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

2: Using continue command in ‘while’ loop

i=11
while(( $i<=20 ))
>do
> ((++i))
> if(( $i==15 ))
> then
> continue
> fi
> echo $i
> done
Output
12
13
14
16
17
18
19
20
21

3: Displaying help information of continue command

continue --help