Jump to content

If then else vs Switch case?


Recommended Posts

Just for clarification, can multiple Else statements be done? For instance (i took this from the help file):

If $var > 0 Then
    MsgBox(4096,"", "Value is positive.")
ElseIf $var < 0 Then
    MsgBox(4096,"", "Value is negative.")
Else
    If StringIsXDigit ($var) Then
        MsgBox(4096,"", "Value might be hexadecimal!")
    Else
        MsgBox(4096,"", "Value is either a string or is zero.");<----instead of ending it here, could it continue indefinitely
;by continuously adding if else ?
    EndIf
EndIf

The help file says that Switch case would be the best if i wanted to compare 1 expression against multiple values, however, I am confused as to how a switch case works which is why im more inclined to use a if then else statement. If multiple else statements cannot be done, could someone kindly explain how switch case works? Or point me to an easier to understand help file as I am new.

Edited by Fickle
Link to comment
Share on other sites

Switch and If are the same (just that Switch looks nicer when you have a big one), and no you can't have multiple Else. How would that work anyway? Else runs when everything else is False, so multiple instead of one doesn't make any bloody sense at all.

Unless you're talking about ElseIf, but that makes even less sense as the helpfile clearly state that you can have as many as you want, and even far less sense when you remember that it would take you less than a minute to try yourself.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...