Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
mwallman
Creator III
Creator III

Can anyone teach me an Intermediate example of Switch...Case statement please?

Hello all,

Can anybody please show an example of Switch Case statement and how it works with an intermediate-advanced example for some data?

I would like to understand it better

3 Replies
jonathandienst
Partner - Champion III
Partner - Champion III

The switch is a script control structure that functions like a series elseif statements:

if ... then ...

elseif ...

elseif ...

elseif ...

...

else ...

end if

switch <expression>

case 1               // execute if statement evaluates to 1

     ...

case 2               // execute if statement evaluates to 2

     ...

default               // execute if no case statement match (like a final "else")

     ...

end switch

Unlike mainstream programming languages, there is no "break" statement. Each "case" is an implicit break for the case above.

PS - I don't think i have ever used it in a real application, but YMMV

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
mwallman
Creator III
Creator III
Author

Hi,

Thank you for the replies but I am still not finding a practical example. Could someone share a practical one please?

Why would you use Switch Case statements? What are the advantages and disadvantages of this function?