Controlling Loop Execution: continue

Learn how we can control the execution of a loop using continue.

We'll cover the following

continue

The continue Bash built-in skips the current loop iteration. The loop does not stop in this case. It starts the next iteration instead.

Here is an example of using continue. Let’s suppose we calculate the sum of positive integers of some array. To do so, we need to distinguish the signs of the integers. The if statement can solve this for us. If the sign is positive, we add the integer to the result. The for-sum.sh shows the script that does it.

Click on the “Run” button and then execute the file.

Get hands-on with 1200+ tech skills courses.