#include <iostream>
using namespace std;
int main() {
int n = 1; // initialising n with 1
int num = 2 * n;
do {
cout << "value =" << num << endl;
n = n++;
} while (n <= 10); // intents to print "value = 2n for all 'n' from 1 to 10
return 0;
}
It just keeps on displaying 2.
n
is getting incremented, but the value of num
is not changing. Also the counting doesn't terminate.
Output:
value =2
value =2
value =2
value =2
value =2
value =2
value =2
value =2
value =2
value =2
value =2
value =2
value =2
value =2
value =2
value =2
I guess it has something to do with the logic I used. Would love to know how to go about questions that uses loops.