different ways to write for loop in c++ code example

Example 1: for loops in cpp

for(int i=0; i<=limit; i++)
{
	//statement
}

Example 2: create loop c++

// There are 2 loops in ++ :

while(1==1){  }
//    |  |   | 
//     |   What happens while condition is true
//     |    
//    the condition


//for loop

for (int i; i < 10; i++){    }
//   |___|  |___|   |_|  |__|
//     |      |      |     | 
//     |      |      |     what happens when conditons is true
//     |      |     what happens each time loop is reapeted
//     |      The condition in wich the loop is true
//     a variable declaratoin

Example 3: c++ for

for (statement 1; statement 2; statement 3) {
  // code block to be executed
}
//Statement 1 is executed (one time) before the execution of the code block.

//Statement 2 defines the condition for executing the code block.

//Statement 3 is executed (every time) after the code block has been executed.

//The example below will print the numbers 0 to 4:

Example
for (int i = 0; i < 5; i++) {
  cout << i << "\n";
}

Tags:

Css Example