loop, while, and for. Notably, the loop construct repeats indefinitely until it is explicitly stopped with a break statement.

Basic Looping with loop
A basic loop in Rust starts with the loop keyword followed by a block enclosed in curly braces. Inside these braces, you can place the code that you want to repeat indefinitely. For example:
break statement. In the following example, a counter is incremented until it reaches 5. Once the counter equals 5, the break statement terminates the loop:
break statement. In this example, the loop increments the counter until it reaches 10, then returns count * 2 which is stored in the result variable:
Loop Labels for Nested Loops
Rust allows you to label loops to make it easier to control nested loops. Labels are defined by a single quote (') followed by the label name. This feature is especially useful when you need to break out of or continue a specific loop in a nested structure.

'outer. An inner loop runs without a label. The inner loop breaks when inner_count reaches 2, but if outer_count reaches 3, the break 'outer statement exits the outer loop entirely:
Skipping Iterations with continue
The continue statement in Rust functions similarly to those in languages like C or Python. When encountered, it skips the rest of the current iteration and immediately moves to the next one. In the example below, a for loop iterates over a range from 1 to 5, and skips the iteration when the counter is 3:
- Basic loops are created using the
loopconstruct and continue indefinitely until abreakstatement is encountered. - Loop labels allow you to manage control flow in nested loop scenarios.
- Use
breakto exit a loop immediately and optionally return a value. - The
continuestatement skips the remainder of the loop’s current iteration.
