On this page
article
Continue Statement
Continue Statement
- What Is a continue Statement?
The continue statement, when encountered inside a loop, skips the execution of the rest of the statements in the loop’s body for the current iteration and returns the control to the start of the loop.
Using With a for Loop
- Below is an example of a continue expression, using a for loop.
- The range defined in the for loop is from
0
to10
with var variable used for iterating over the loop- Within the for loop:
- The value of var is printed
- When the value of
var
is equal to4
, the control goes to the start of the loop - The loop executes until the upper bound for the defined range is reached
- Within the for loop:
output:-
Using With a while Loop
- Below is an example of continue expression, using a while loop.
- A mutable variable var is defined
- A boolean variable found is defined
- Within the while loop body:
- The value of var is printed
- When the value of var is equal to
4
, the control goes to the start of the loop. - The loop executes until the value of found does not equal true.
Output
Using With a loop
- Below is an example of continue expression, using a loop .
- A mutable variable var is defined
- A boolean variable found is defined
- Within the loop body:
- The value of var is printed
- When the value of var is equal to
4
, the control goes to the start of the loop - The loop executes infinitely
Note: This code widget will give an error, ❌, due to limitations of our platform but on the local machine, it will run an infinite loop.
Quiz
Test your understanding of continue statement in Rust.
Last updated a year ago.