0

Why we got 1 in the output??

as we run the while loop for the first time...num has its value as 1 ...so after executing num= num+1 ..the first output should be 2 bcoz we are adding 1+1 ....pls explain how

1st Jul 2017, 11:18 AM
PRADEEP YADAV
PRADEEP YADAV - avatar
2 Answers
+ 5
..... you are printing to the screen before the addition...
1st Jul 2017, 11:57 AM
jay
jay - avatar
0
int num = 1; while (num < 6) { cout << "Number: " << num << endl; num = num + 1; } /* Outputs Number: 1 Number: 2 Number: 3 Number: 4 Number: 5 */
1st Jul 2017, 11:30 AM
PRADEEP YADAV
PRADEEP YADAV - avatar