For Loop In Rust

Authors

For Loop In Rust

A for loop enables a certain collection of statements to be performed repeatedly inside the loop until a specific condition is met.

Syntax

for variable in expression {
    loop code
}

In Rust, the expression for a for loop is an iterator that returns a list of values. The loop is iterated once for each element. The loop code can then use this value, which is now bound to a variable, to carry out operations. After the loop code has run, the procedure is repeated while retrieving the following value from the iterator. When there are no more values, the loop ends.

fn main() {
  // for loop to print the value of iterators
  for x in 0..10 {
    println!("value of iterator is: {}", x);
  }
}
TrackingJoy