DemonEdge,
Quote:
int x = 0;
int y = 0;
while(!x)
{
|
'while' condition is true, and the function is evaluated..so it follows...
Quote:
while(!x)
{
switch(x)
{
case 0:
for(x=3;x>0;x--)
{
|
Now, here at the switch statement ,value of x is 0. So switch is executed i.e case 0 condition. ..
Quote:
for(x=3;x>0;x--)
{
switch(y)
{
case 0:
cout<<"yes"<<endl;
break;
default:
cout<<"no"<<endl;
break;
}
}
|
For 3 loops the above block will be executed [value of y is 0 , switch(y) satisfies].Produces output "yes" "yes" "yes"
Quote:
if(y>0)
x = y;
break;
case 1:
break;
case 2:
breal;
}
y++;
}
}
|
none of the above statement will be excuted except for y++ .so y=1 now.
The while loop continues , and enters the switch(y) fn where case 'default' is satisified ,so prints "no" no" "no".
y>0 satisifies, x=y is done , the while loop is terminated as while(!x) is false