0

While loop

#include <iostream> using namespace std; int main() { int num = 1; while (num < 6) { cout << "Number: " << num << endl; num = num++; } return 0; } i tried num = ++num and the loop stopped after "number 5" Why does num = num++ create a continous loop without end because it continues to print "number 1" ?

27th Apr 2018, 8:54 AM
Olorunmbe Nathaniel
Olorunmbe Nathaniel - avatar
3 Answers
0
num = num++ =1 And num<6; Loop keeps going over and over. It doesn't increase. where num = ++num=2 and keeps increasing. So when it hits limit it breaks the loop.
27th Apr 2018, 9:17 AM
Akib
Akib - avatar