2
0
mirror of https://github.com/chubin/cheat.sheets synced 2024-11-19 03:25:44 +00:00
cheat.sheets/sheets/_cpp/loops

20 lines
353 B
Plaintext
Raw Normal View History

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