case statement


case statement

switch statement

case statement

A variation of the if-then-else programming statement that is used when several ifs are required in a row. The following C example tests the variable KEY1 and performs functions based on the results. For an example of how the case statement was used in an actual program, see event loop.

switch (key1) {case '+': add(); break;case '-': subtract(); break;case '*': multiply(); break;case '/': divide(); break;}