1. Consider the for-loop statement in pseudocode below and answer the following questions number = 15
do while (number >=-25)
Display “number = “, number
number = number -2
Loop
1.1 Rewrite the do while loop using a for-loop in a C++ syntax. Write only the for loop statement, do not write the other instructions inside the body of the loop.
1.2 Rewrite the do while loop above in C++ syntax.
1.3 How many times will the loop execute?
1.4 The value of number after execution of the loop.
1.1
for (int number = 15; number >= -25; number -= 2)
1.2
int number = 15;
while (number >= -25) {
cout << "number = " << number << endl;
number -= 2;
}
1.3
The loop will be executed 21 times
1.4
After execution of the loop, the variable number will have a value of -27
Comments
Leave a comment