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?
3 Respostas
+ 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
+ 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.
0
There is no specific reason for it... and If there is any then tell us...