What is counter value?
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.
Sw=2 counter =2
So the final counter value is 2