C++ for loop code example

Example 1: c++ for loop

//'i' can be any number
//Can be any comparison operater 
//can be any number compared
//can be any mathmatic operater

for (int i = 0; i<100; i++){
//Do thing
}

//more info on operaters
//https://www.w3schools.com/cpp/cpp_operators.asp

Example 2: how to make a Loop in c++

for (int i; i < 10; i++)
{
  cout << i << "\n";
}

Example 3: for loops in cpp

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

Example 4: for loop c++

#include <iostream>

using namespace std;

int main(){
 
  int i; //initialize integer
  //i starts at 0 and stops at 4, as 5 is not < 5
  for (i = 0; i < 5; i++){ //i++ means add 1 to i each iteration
    cout << "number " + i << endl; //print 5 times
  }
  return 0;
}
//output:
/*
number 0
number 1
number 2
number 3
number 4
*/

Example 5: for loop c++

for (/* init var */;/* break condition */;/* mathmatic operation */) {
  // do something
}

Example 6: c++ for loop

#include <iostream>

using namespace std;

int main()
{
	int abc = 10;
	for (int /*what ever letter you want (here I used i)*/i = 0; i < /*can be any comparison operater(here i used <)*/abc/*any variable to compare*/; i++/*what should happen when the code inside the for loop is executed*/)
    {
    	/*here do some thing that you want to repet*/
        cout << i << "\n";/*this will print 1, 2, 3, 4... until 10*/
    }
}

Tags:

Cpp Example