R
rivkaumiller
while((c=getchar())!=EOF){
switch(flower){
case rose:
switch(color){
case white:
// do something 1
case pink:
// do something 2
...
}
case lily:
switch(color){
case white:
// do something 1
case pink:
// do something 2
...
}
...
case unique:
// do something 3
...
}
}
basically, I can write the above statement completely using
if(flower==rose) goto
if(color==white) goto
type statements.
unfortunately, some of the flowers have strange names such as the ascii value of '/' or other characters like '%' and so on so switch-case gives me brevity.
However, inside switch-case I want to jump to certain cases before breaking to the end.
for example from (rose,pink) I may want to goto unique: . Can I do that by a
goto unique: ?
Note its a unique label. It is also an alias for another case where I want to do something unique before going into the while cycle which will read a char and then break down to the end.
I have a few choices.
One is that I have that label outside both of the switch-cases and its not a switch case label. There, if I want to fall through the cases below, I will have to use goto end: for all of them.
However, I can also put some dummy labels with break in the outermost switch-case and use them as labels.
In crux, the question is if I can use a switch-case's case-colon as a label for goto or not?
If so, then can I use a case like '%'-colon as a case for goto using
goto '%' ?
Thanks
switch(flower){
case rose:
switch(color){
case white:
// do something 1
case pink:
// do something 2
...
}
case lily:
switch(color){
case white:
// do something 1
case pink:
// do something 2
...
}
...
case unique:
// do something 3
...
}
}
basically, I can write the above statement completely using
if(flower==rose) goto
if(color==white) goto
type statements.
unfortunately, some of the flowers have strange names such as the ascii value of '/' or other characters like '%' and so on so switch-case gives me brevity.
However, inside switch-case I want to jump to certain cases before breaking to the end.
for example from (rose,pink) I may want to goto unique: . Can I do that by a
goto unique: ?
Note its a unique label. It is also an alias for another case where I want to do something unique before going into the while cycle which will read a char and then break down to the end.
I have a few choices.
One is that I have that label outside both of the switch-cases and its not a switch case label. There, if I want to fall through the cases below, I will have to use goto end: for all of them.
However, I can also put some dummy labels with break in the outermost switch-case and use them as labels.
In crux, the question is if I can use a switch-case's case-colon as a label for goto or not?
If so, then can I use a case like '%'-colon as a case for goto using
goto '%' ?
Thanks