how to use loop in c++ code example
Example 1: how to make a Loop in c++
for (int i; i < 10; i++)
{
cout << i << "\n";
}
Example 2: 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
*/