The SWITCH statement


  • registered

    [code] switch LABEL EXPRESSION case LABEL VALUE[ VALUE] ... [exitswitch LABEL] ... [default LABEL ... [exitswitch LABEL] ...] endswitch LABEL [/code] where... [list]
  • [*]LABEL = Following a similar construct as my loop construct suggestion, this switch construct uses a LABEL to allow for nested switch-case's.
  • [*]EXPRESSION = A numerical type expression, be it a variable expansion or a numerical ifcheck.
  • [*]case = marks a choice in the switch
  • [*]VALUE = Used in individual cases. When a case has two values, they act as a RANGE, in which all values
  • [*]exitswitch = breaks out of the switch, causing the script to search for the endswitch with the matching label.
  • [*]default = used as the case of last resort when no other case matches it. The default case MUST go at the end, without creating more complicated code to handle it in other places. Should there be no default case, it will just exit the switch.
  • [/list] Much like C style switch-case statements, execution would FALL through subsequent sections of code without an EXITSWITCH to break out. I prefer this mechanism over segregated blocks. When deciding a case to enter, it should be first match first enter, so duplicate cases would ignore subsequent cases, once it finds a match.

Log in to reply