0

while loop

int num = 1; while (num < 6) { cout << "Number: " << num << endl; num = num +1; } in this case o/p is:Number: 1 Number: 2 Number: 3 Number: 4 Number: 5 Number: 6 but instead of num=num+1 if i write num=num++ it is giving o/p as number:1 number:1 . . . infinite times why?

27th Dec 2016, 7:09 AM
pankaj sarda
pankaj sarda - avatar
3 odpowiedzi
0
you should user num++ num = num + 1 or ++num or num++
27th Dec 2016, 11:02 AM
Matin Zadehdolatabad
Matin Zadehdolatabad - avatar
0
That u have written is num = num = num + 1
27th Dec 2016, 11:03 AM
Matin Zadehdolatabad
Matin Zadehdolatabad - avatar
0
It will give you syntax error
27th Dec 2016, 11:03 AM
Matin Zadehdolatabad
Matin Zadehdolatabad - avatar