, ,


C ++ Programming Language For Hackers Tutorials

The condition of a switch statement could be a value. The case says that if it’s the value of no matter is at that time case then do whatever follows the colon. The break is employed to interrupt out of the case statements. Break could be a keyword that breaks out of the code block, sometimes encircled by braces, that it’s in. During this case, break prevents the program from falling through and death penalty the code all told the opposite case statements. A very important issue to notice regarding the switch statement is that the case values might solely be constant integral expressions. Sadly, it is not legal to use case like this:


int a = 10;
int b = 10;
int c = 20; switch ( a ) {
case b:
// Code
case c:
// Code
// Code

The default case is optimal, however it’s wise embrace it because it handles any sudden cases. Switch statements is an easy thanks to write long if statements once the necessities are met. Typically it are often wont to method input from a user.

What do you think?

1 point
Upvote Downvote

Total votes: 15

Upvotes: 8

Upvotes percentage: 53.333333%

Downvotes: 7

Downvotes percentage: 46.666667%

Don't worry, we don't spam

Leave a Reply

Your email address will not be published. Required fields are marked *