for (in ) c++ code example
Example 1: 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 2: for c++
#include <iostream>
#include <stdlib.h>
/*====================================
* eXcript.com
* fb.com/eXcript
* ====================================*/
using namespace std;
int main() {
for(int i = 0; i <= 10; i++){
cout << "O valor de i eh igual: " << i << endl;
}
system("pause");
return 0;
}