+ 1
Is the output od the following program, right? Is it common to include the increment before the other statements in a loop?
int num = 1; while (num < 6) { num = num + 1; cout << "Number: " << num << endl; } /* Outputs Number: 2 Number: 3 Number: 4 Number: 5 Number: 6 */
3 Respostas
+ 1
Yeah, doing:
cout << "Number: " << ++num << endl;
Will result in the same output.
0
it makes no real difference
0
Locating the Incremental value is based on the requirement. Usually while loop holds the increment/decrement at the end of the loop.
Here we missed the output for value '1'.