Posts

Showing posts with the label switch statement in c++

Switch statement in C++ programming language

Image
 Switch statement in C++ programming language In programming languages we have studied about conditional statements in which accross given set of conditions we chose any specific condition and run the block of code as per that condition. There are other techniques that we call control statement or decision making statements . The Switch statement is one of the very important example of such control statement  or deciison making statements . The switch is used to to select and execute one block of code from several possible options. The Switch statement is alternatively used in place of a long if-else-if ladder statement which is an example of conditional statement . It is more cleaner as compared to if-else-if ladder and also it is more efficient for the compiler to process it. Basic Syntax of Switch Statement in C++ programming language Basic Working of Switch Statement in C++ Programming Language In Switch statement we usually take an input from user th...

Switch statement in c programming language

Image
  Switch statement in c programming language What Is a switch statement? The switch statement is a conditional statement that we use to run different code sections based on some conditions. The switch statement also works like the if else-if else ladder statement. As we know in the else-if ladder statement we implement multiple conditions it is exactly how the switch statement works. In the switch statement, we use the term case: that tells us about any specific condition within the switch expression area switch(expression).   What is the syntax of a switch statement in c programming switch(Some_Epression) { case value1: // insert code here break; case value2: // insert code here break; default: // insert code here } Rules and regulations of switch statement: Always remember that the expressions that are used within the switch statement i.e. switch(expression), this expression must be a single character or an integer value. As discussed earlier  case: ...