Rust Tutorial : Loops
from tutorialspoint.com

Definite Loop
the number of iterations of which is definite/fixed is termed as a definite loop
the for loop is an implementation of a definite loop
syntax
for temp_variable in lower_bound..upper_bound {
   //statements
}
example
fn main(){
   for x in 1..11{ // 11 is not inclusive
      if x==5 {
         continue;
      }
      println!("x is {}",x);
   }
}
Indefinite Loop
While Loop
the while loop executes the instructions each time the condition specified evaluates to true
example
fn main(){
   let mut x = 0;
   while x < 10{
      x+=1;
      println!("inside loop x value is {}",x);
   }
   println!("outside loop x value is {}",x);
}
Loop
the loop is a while(true) indefinite loop
example
fn main(){
   //while true

   let mut x = 0;
   loop {
      x+=1;
      println!("x={}",x);

      if x==15 {
         break;
      }
   }
}
break statement is used to take the control out of a construct

Continue Statement
the continue statement skips the subsequent statements in the current iteration
returns the controlto the beginning of the loop
continue does not exit the loop
terminates the current iteration and starts the subsequent iteration
example
fn main() {

   let mut count = 0;

   for num in 0..21 {
      if num % 2==0 {
         continue;
      }
      count+=1;
   }
   println! (" The count of odd values between 0 and 20 is: {} ",count);
   //outputs 10
}
index