+ 1
Output is 5. Anyone knows how.?
int a = 1 while(a++<=1) while(a++ <= 2); cout<< a;
2 odpowiedzi
+ 7
This is how the program executes:
Outer loop:
a++ <= 1 -> true
a = 2
Inner loop:
a++ <= 2 -> true
a = 3
a++ <= 2 -> false
a = 4, since it was still incremented during the condition
Inner loop terminates.
Outer loop:
a++ <= 1 -> false
a = 5, same as above
Outer loop terminates.
Keep in mind 'a' will be incremented once more even if the condition evaluates to false and the loop terminates.
+ 3
Excellent explanation Shadow 👍👍👍