switch

Switch Statement in C++

The switch statement is a special multiway decision maker that tests whether an expression matches one of the number of constant values accordingly. switch statement allows the user to choose a statement or a group of statements among several alternatives. The switch statement is useful when a variable is compared with different constants, and in case it is equal to a constant, a set of statements would be executed. The general form of the switch statement is as follows: switch (expression) { case constant 1: statement; case constant 2: statement; ………. ………. case constant n: statement; default: statement; } In this general form: 1) The expression, whose value is being compared, may be any valid expression but not a floating point expression 2) The The value that follows the keyword case may only be constants. They cannot be expressions. They may be an integer or characters, but not the floating...

Control Statements in C Plus Plus (C++)

Control statements alter the flow of execution of the programs. Control statements can be broadly divided into three categories: Decision-making or Conditional Statements (Branching and Selection) if statement if-else statement switch statement Loop Statements for statement while statement do-while statement Breaking Control Statements break statement continue statement goto statement