X



Home>Tutorial>

What is JavaScript continue Statement With Examples

Nuelson Penuel Monday, July 31, 2023 Javascript

JavaScript Continue Statement

The `continue` statement is a control statement in JavaScript that is used to skip the current iteration of a loop, such as `for` or `while`, and move to the next iteration. It is often used within loops in conjunction with conditional statements to selectively skip specific iterations based on certain conditions.

Syntax o JavaScript Continue Statement

The syntax of the `continue` statement is as follows:
continue;
When the `continue` statement is encountered within a loop, it immediately stops the execution of the current iteration and jumps to the next iteration.

Examples of JavaScript 'continue' Statement

Here is how the `continue` statement works in different types of loops: 1. `for` loop:
   for (initialization; condition; increment/decrement) {
     // code block
     continue;
     // more code
   }
   
In a `for` loop, the `continue` statement skips the remaining code within the loop body for the current iteration and moves on to the next iteration. 2. `while` loop:
   while (condition) {
     // code block
     continue;
     // more code
   }
   
Similarly, in a `while` loop, the `continue` statement skips the remaining code within the loop body for the current iteration and moves on to the next iteration. 3. `do-while` loop:
   do {
     // code block
     continue;
     // more code
   } while (condition);
   
In a `do-while` loop, the `continue` statement has the same effect as it does in `for` and `while` loops, whereby it skips the remaining code within the loop body for the current iteration and moves on to the next iteration.

Conclusion

It's important to note that the `continue` statement only affects the current iteration of the loop. It does not terminate or exit the loop completely. The `continue` statement is often used in combination with conditional statements to control the flow of the loop and selectively skip certain iterations based on specific conditions.

| | Views(186)

See Demo | Download File


Add your comment. Indicate code using code tag


Words: 0 | Chars: 0 | Reading Duration: 0



Images Attachment




Emmason Integratded Services(2017-2024)
All Rights Reserved
Designed and Maintained By Emmason Integrated Services