mirror of
https://github.com/chubin/cheat.sheets
synced 2024-11-15 06:12:59 +00:00
907c3cad09
Recursively.
20 lines
353 B
Plaintext
20 lines
353 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 );
|