Switch

In this section, we will guide you on how to use the Switch block.

Use Cases

In programming languages, a switch statement is a control flow statement used to execute different blocks of code based on the value of an expression. It provides a more concise and readable structure for handling multiple conditional branches compared to an if statement.

Syntax of a switch statement:

switch (expression) {
  case value1:
    // code to be executed if expression is equal to value1
    break;
  case value2:
    // code to be executed if expression is equal to value2
    break;
  // ... more cases
  default:
    // code to be executed if expression is not equal to any of the above values
}

In Tapicker, the Switch block works similarly to the switch statement in programming languages, but with a few differences:

  1. You can set conditions for each case without needing an expression on the switch itself.
  2. You need to add a default condition manually if required.

switch

Adding a Case

Adding a case is simple. Just click the small icon below to add a new case.

add-case

Setting Conditions

Setting conditions for a case works the same way as in the Condition block. Please refer to that section for details.

set-condition

Setting a Default (Fallback)

To set a default case, simply place the case at the end (far right) and ensure that its condition always evaluates to true.

default

Break

If there is no break, the program will continue executing the next case. By adding a break, the code will exit the switch statement after executing one case block.

break

For usage of Break block, see this section.