0

Tell me why?

int num = 1; while (num < 6) { cout << "Number: " << num << endl; num = num + 3; } /* Outputs Number: 1 Number: 4 */ why 3 is added in num?

1st Aug 2017, 4:12 PM
Mohd Kaif
Mohd Kaif - avatar
3 Answers
+ 7
for first time (num<6)true { cout<<number:<<num<<endl; //number:1 num=num+3; //4 } for second time now (num =4) (num<6) true { cout<<number:<<num<<endl;. //number:4 num=num+3;. //7 } for third time num=7 (num <6 )false so the loop is terminated
1st Aug 2017, 4:37 PM
P R
P R - avatar
+ 2
I can't see any particular reason for it. It's certainly not essential for the loop to work. I guess more info or some context is needed to understand why it's there. Could be just an example of how variables work in loops.
1st Aug 2017, 4:41 PM
Bagshot
Bagshot - avatar
0
There is no specific reason for it... and If there is any then tell us...
1st Aug 2017, 4:47 PM
Gaurav Singh