, ,

C++ PROGRAMMING LANGUAGE FOR HACKERS – Switch Case [5]

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
break;
case c:
// Code
break;
default:
// Code
break;
}

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?

3 points
Upvote Downvote

Total votes: 11

Upvotes: 7

Upvotes percentage: 63.636364%

Downvotes: 4

Downvotes percentage: 36.363636%