In a switch
/ case
statement, the case
statements is for checking the condition, so why should it execute the statements which are false? Even if it continues execution of all the cases up to the end of the program if break
is not given, won't the case
statement check the condition. Isn't its internal working same as if
/ else
statements? If not, then how does it work internally? Language: C
No, a case label (which isn't a statement) doesn't check any condition. In fact it doesn't do anything at all (notice how you can have multiple cases in a row?) and doesn't produce any code. Upon entering the switch, execution jumps to the matching case. And that's it. Once you're in the block, the labels don't do anything, but a break
will get you out.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.