70
Views
11
Comments
Different between Switch and If

Hi, I'm new here. I know Switch and If are conditional paths. But what is the different between them? When do we use them?

2026-01-28 16-57-48
Mihai Melencu
Champion

Hello @Toumtam Phiphack ,

  • If 

Simple True/False check. Used in UI screens to show/hide stuff and also in server/client actions. Can also be used in expressions.

Use if when you just need a yes/no decision like validating a form.

  • Switch 

Used when there are multiple options. Works in server/client actions, not in UI. You can use switch when you have many possible cases.

Example: Run different logic based on status (Completed, In-Progress, etc.).

2026-02-26 06-29-24
Rahul
 
MVP

In OutSystems, "if" is a basic conditional statement that executes a block of code only if a specified condition is true, while "switch" is a more complex conditional tool that allows you to choose one block of code to execute based on the value of a variable, essentially acting like a series of "if-else if" checks for different possible values. 


Also One Switch is used for toggle between true/false.


2025-02-07 09-54-44
Sivasakthi Munusamy

Hi @Toumtam Phiphack ,

 If Condition

  • The If condition is used when you need to evaluate a single condition and take one of two possible paths (True or False).
  • It is typically used inside screens, widgets, or expressions to show or hide UI elements.

Switch Condition

  • The Switch condition is used when you have multiple possible values and need to execute different paths based on the value.
  • It is mainly used in logic flows where multiple conditions determine different actions.

Thanks,

sivasakthi

2026-02-16 05-51-10
Sahana K

Hi @Toumtam Phiphack ,

The "If" widget is used to conditionally display content based on a boolean expression or condition being true or false.

The "Switch" widget works like a multi-conditional statement allowing different content to be displayed based on the value of a given expression. 

And also please refer this document
https://success.outsystems.com/documentation/11/reference/outsystems_language/logic/implementing_logic/logic_tools/switch/
https://success.outsystems.com/documentation/11/reference/outsystems_language/logic/implementing_logic/logic_tools/if/

Thanks,
Sahana

2024-01-04 09-21-21
Venkatesaiya

Hi Toumtam,

Please refer this Documentation Switch and take look on demo switch statement video Video link

2024-01-04 09-21-21
Venkatesaiya

For If statement If statemet  and demo of If statement video link

2022-12-30 07-28-09
Navneet Garg

In OutSystems, the primary difference between a "switch" and an "if" statement is that a "switch" allows you to check a single variable against multiple possible values, while an "if" statement only checks a single condition against a Boolean value, making "switch" more efficient when dealing with multiple distinct options for a single variable. 


If you have lots of values to check switch is better and cleaner way.

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

This is wrong, a Switch allows you to combine multiple conditions in a single statement, it is not (like in C or Java) used "to check a single variable against multiple possible values". You can very well check totally unrelated conditions.

Also, an If statement produces a boolean value, it is not used to check against a boolean value.

As for Switch being "cleaner", that's a discussion to have. I personally don't like Switches as they easily make your flow impossible to layout in a satisfactory manner.

2024-07-05 14-16-55
Daniël Kuhlmann
 
MVP

It is a basic question, that when searched in the OutSystems documentation, internet, or even asked to ChatGPT is answered correctly within a second. Yet we have 7 people doing the search for you.

No one can complain that the OutSystems community is not active ;)

2025-02-10 08-07-05
Sudha Narayanan

Hi @Toumtam Phiphack ,

In IF it evaluates a single condition and executes one of two branches like (True/False). 

In Switch it  Selects one case from multiple possible conditions. 

For simple example based on outsytem

In IF condition, i want to show the username based on userid in expression widget,if the userid is not created it will show Create user .For this we can enclose the container in if,in condition we can give Userid=nullidentifier .in true branch we can give the create User , in Flase we can show the user Id.

In swich condition,

I want to show the Daytype of the week means,we can user the Dayofweek() builtinfunction it returns the day in number 1 for Sunday, 2 for Monday, etc .

In  Switch Widget,

Case 1: If DayOfWeek = 1, in text Weekend (Sunday)

Case 2: If DayOfWeek = 7, in text Weekend (Saturday)

otherwise   it shows the Weekday

the output we can show like

If today is Monday means Weekday. If today is Saturday means Weekend.

Thanks,

Sudha Narayanan

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

Hi Toumtam,

If you've read all the answers you're up to speed with the differences. However, one thing to understand is that the OutSystems Switch is not, like it is in many other languages, a selection of multiple values of a single variable. Basically there's no difference between a Switch with three conditions and three Ifs with these conditions below each other. So it's up to your personal preference when to use a Switch instead of multiple Ifs.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.