...

/

Definite Loop - For Loop

Definite Loop - For Loop

This lesson will teach about finite loop, i.e., for loop.

What Is a for Loop?

A for loop is a definite loop, meaning, the number of iterations is defined.

Syntax

The for loop is followed by a variable that iterates over a list of values.

The general syntax is :

Example

The following example uses a for loop that prints 5 numbers.

Press + to interact
fn main() {
//define a for loop
for i in 0..5 {
println!("{}", i);
}
}

Explanation

for loop definition

...