I know the syntax for writing a case break statement, but I’m wondering if this is allowed:
CODE:
case 'p':
{
printf("Give number: ");
scanf("%d, &int_1);
if int_1=5;{
printf("Played: you win");
}
break;
}
Basically I’m just wondering if this is something that’s possible to do, I know the code is incomplete but I don’t want anyone to think I’m trying to elicit specific answers. I simply seek a better understanding of applying conditionals to my programs. Thank you.
EDIT: Other than in the tags, I didn’t specify so just in case this isn’t clear, this is in C.
The short answer is yes, you can nest an
ifinside ofswtich/casestatement (or vice versa). If you want to badly enough, you could have a loop containing aswitchcontaining severalifs, etc.Bottom line: the limit on nesting various kinds of statements is normally imposed by such considerations as taste and readability, not limitations built into the language.