for loop in cpp 1

for loop in cpp



for (int i = 0; i < 10; i++){
  //Do something as long as i is less than 10, 
  //In that case it will loop 10 times
  //use break; to restart the loop whenever you want to cancel the loops.
  cout << i;
  
  //at the end, remember i will be increased by 1.
}

//output 0123456789

Here is what the above code is Doing:
1. We create a variable called i and set it to 0.
2. We create a for loop that will run as long as i is less than 10.
3. We print the value of i.
4. We increase the value of i by 1.
5. We go back to step 2.

Similar Posts