Help on the switch statement?


Hello :smile:

Hope your all ok ? :smile:

so I dont completely understand the switch statement :confused:

Any help would be awesome :smile:


Could you be a bit more precise?
The syntax is

case ... :
case ... :

where the values after case and between the : are compared to the value after (). The first matching one is chosen and default is kind of like the else that gathers the rest. break; let's you skip this because otherwise you would go on with the code below even this the value after case is not matched.


Sorry I wasn't that clear aha,

What I meant is, Like basically how do they work, what does the switch statment do ? :smile:

I Know it explains it, but I cant understand it :confused:


Maybe also have a look at this definition in the glossary:

Acts like a big if / else if / else chain. Checks a value against a list
 of cases, and executes the first case that is true. It goes on 
executing all other cases it finds after the first true case till it 
finds a breaking statement,after which it breaks out of the switch If it
 does not find any matching case , it executes the default case.


Ah thanks a lot for explaining :smile: , I was just super confused by it aha , thanks again :smile: