TrumanWong

continue

End this loop and continue executing the next for, while or until loop.

Summary

continue [n]

The main purpose

  • End this loop and continue to execute the next for, while or until loop; you can specify which level of loop to continue execution from.

Parameters

n (optional): an integer greater than or equal to 1, used to specify which level of loop to continue execution from.

return value

The return status is success unless n is less than 1.

example

# The default value of the optional parameter n of continue is 1.
for((i=3;i>0;i--)); do
   # Jump to the inner for loop to continue execution.
   for((j=3;j>0;j--)); do
     if((j==2)); then
       # The result is the same when changed to continue 1
       continue
     fi
   printf "%s %s\n" ${i} ${j}
   done
done
# Output results
3 3
3 1
twenty three
twenty one
1 3
1 1
# When n is 2:
# Jump to the outer for loop to continue execution.
for((i=3;i>0;i--)); do
   for((j=3;j>0;j--)); do
     if((j==2)); then
       continue 2
     fi
   printf "%s %s\n" ${i} ${j}
   done
done
# Output results
3 3
twenty three
1 3

Notice

  1. This command is a built-in bash command. For related help information, please see the help command.