Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
continue | Loops
Introduction to JavaScript
course content

Contenido del Curso

Introduction to JavaScript

Introduction to JavaScript

1. Basic Concepts
2. Variables and Data Types
3. Basic Operations
4. Conditional Statements
5. Loops
6. Functions

bookcontinue

The continue keyword allows you to skip the remaining code within a loop for the current iteration and proceed to the next iteration.

Example 1: Skipping Early Iterations

1234567
for (let i = 0; i < 10; i++) { if (i < 5) { continue; } console.log("i =", i); }
copy

In this example, the continue keyword is used to skip iterations of the loop where i is less than 5. As a result, only iterations with i values in the range [5, 9] execute the code inside the loop.

Example 2: Skipping a Specific Iteration

123456789
for (let i = 1; i <= 5; i++) { console.log("Iteration started:", i); if (i == 3) { continue; // Skip the end of the 3rd iteration } console.log("- Iteration ended:", i); }
copy

Here, the continue statement is used to skip the end of the 3rd iteration, resulting in the output of "Iteration started" and "Iteration ended" messages for all iterations except the one where i equals 3.

Note

The continue keyword works similarly to break, but instead of terminating the loop entirely, it only skips the current iteration and proceeds with the next one. This behavior can be handy for fine-grained control of loop execution.

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 5. Capítulo 7
We're sorry to hear that something went wrong. What happened?
some-alt