For Loop Function

1
2
3
4
5
6
7
	int a = 3;
	int b = 7;
	int num = 2;
	for (int c = a; c >= b; c--)
		num += c;
	
	cout << num << endl;

Line 4: If 3 is assigned to int c, how can 3 be >= 7?
On c-- you are decreasing the value of c by one. Once you reached the minimum value an int can have, its value would go to the maximum one
Still don't quite understand. How to get num = 4?
It would help if your question were more clear. What exactly are you trying to accomplish? As it is written now, you for loop will never execute.
I am figuring out line 7 ans which is 4.
The code you posted will output 2 as the result. If you're getting something else, either the code you posted is different than what you're running, or there's something strange going on with your compiler.
.....there is no loop going on since 3 >= 7 is a false statement

hence it should output 2 as the result
Topic archived. No new replies allowed.