In the below code the if
condition is overridden by the goto
statement and in the subsequent one, if
condition in switch
is overridden too. Please explain why goto
and switch
is doing this and is there a way to put condition on goto
and inside switch
as well.
int main()
{
int x=3;
goto LABEL;
if(x < 0) {
LABEL: printf("Label executed");
}
printf("\nEND MAIN");
return 0;
}
OUTPUT:
Label executed
END MAIN
int main()
{
int x = 2, y = -5;
switch(x)
{ if( y > 0)
{ case 1:
printf("case 1");
break;
case 2:
printf("\n case 2");
break;
}
case 3:
printf("\n case 3");
break;
default :
printf("\n Exit switch");
}
}
OUTPUT:
case 2