Description
The purpose of this challenge is write various loops using WHILE, DO-WHILE, and FOR statements.
Requirements
Convert the while loop below to a for loop so that it shows the same output. However, there is a bug in it — the code appears to try to show only numbers that are divisible by 2 (it does not). Fix this as you rewrite it to a for loop.
int i = 0; while (i < 100 && i % 2 == 0) { cout << i << " "; i++; } cout << endl;
Convert the do-while loop below to a for loop so that it shows the same output.
int i = 1; do { if (i % 3 == 0) { cout << i << " "; cout << "Alpha" << endl; if ((i + 1) % 10 == 0) { cout << "Omega" << endl; } } i++; } while (i < 100);
CATALOG ID: CPP-LOOP0006
Print Requirements