While statement condition with decrease variable| while statement condition different format

While condition in the decrease variable in the every loop. Is it possible?
sw=3,counter=0;
while((sw-1))
{
++counter;
sw--;
}
What is counter value?
Debugging Answer:
2
Debugging solution:
Whenever it will enter in to the while loop it must statisfy there while loop condition
In these case it will enter the loop till for the sw=2,when it become sw=1
Then while((sw-1)) 1-1=0.so while loop become false .so it does not enter the while loop.
So
Sw=3 counter=1
Sw=2 counter =2
So the final counter value is 2

Post a Comment

0 Comments