2
0
mirror of https://github.com/chubin/cheat.sheets synced 2024-11-11 01:10:31 +00:00
cheat.sheets/sheets/_cpp/loops
2018-05-19 20:40:04 +00:00

20 lines
362 B
Plaintext

// There are only 'for', 'while', and 'do while'
// For loop - Outputs "0 1 2 3 4 5 6 7 8 9"
for( int i=0; i<10; i++ ) {
std::cout << i << " ";
}
// While loop - Outputs "0 1 2 3 4 5 6 7 8 9"
int i = 0;
while( i < 10 ) {
std::cout << i << " ";
i++;
}
// While loop - Outputs "0 "
int i = 0;
do {
std::cout << i << " ";
}while( i<0 );