Switch

Quick Summary

Switch Case is similar to a conditional statement, but it's designed to only check a single value for matches. Where a conditional is great for things like "If the user joined before 2020 and is also a subscriber", Switch Case is more efficient and ideal for simple scenarios like "If the color is red, blue, green, brown, yellow, or orange", when you want each of those options to have different paths.

Conditional vs Switch — which one should you use?

When deciding between using an If/Then statement and a Switch statement, it's important to consider the complexity and clarity of the logic you're implementing. An If/Then statement is ideal for situations where you have several conditions that require different actions. It provides straightforward logic for evaluating true or false scenarios.

On the other hand, a Switch statement is better suited for cases with multiple possible values for a single variable. It makes your function stacks cleaner and more organized by avoiding deep nesting of conditions when the logic involves fixed values. Use If/Then for more advanced conditions and Switch for handling multiple specific scenarios with more concise readability.

Using Switch Case

1

Add a Switch statement to your function stack.

Switch is located under Data Manipulation.

2

Set the value that Switch should be checking.

You can hard code a value here, or specify a variable or input.

3

Set your 'default' functions, if desired.

The Default section of Switch will run if:

  1. No matches are found

  2. You chose to not break out of Switch after a match is found

This is a good spot to insert any "catch-all" situations where you want a standard behavior for unaccounted possibilities.

4

Click to define a behavior based on a specific value.

When adding a new case, you'll be asked to provide the value that determines if this case will run.

You can also choose to either stop the Switch Case statement after the match is found, or execute the functions under Default after matching.

5

Add functions to your case(s)

Click under your cases to add functions to them, or drag and drop functions inside of them. Now, when your Switch function detects that case in the value you specified in step 2, it will execute those functions.

Last updated

Was this helpful?