User Tools

Site Tools


4rpl:commands:switch

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
4rpl:commands:switch [2022/09/07 08:41] – added programming note and 2nd example Karsten754rpl:commands:switch [2024/03/30 17:05] (current) – Change title to lowercase for consistency between flow control Up-Level
Line 6: Line 6:
  
 :!: Available in version 2.4.4 and later. :!: Available in version 2.4.4 and later.
-====== Switch ======+====== switch ======
 switch switch
  
 ===== Description ===== ===== Description =====
 Allow for multiple selection control in a single, more compact form that multiple if/else if/endif endif format. This is intended to improve clarity by reducing otherwise repetitive coding.  Allow for multiple selection control in a single, more compact form that multiple if/else if/endif endif format. This is intended to improve clarity by reducing otherwise repetitive coding. 
 +
 +All code between ''switch'' and ''endswitch'' is evaluated in order, including code written outside of ''case''..''endcase'' statements. Each ''case'' expects an argument that evaluates to True or False at the time of being encountered. If True, the case is executed, and the execution of the switch is ended at the next ''endcase''. If False, the case is skipped and the execution of the code inside the switch continues as normal.
  
 === Programming note === === Programming note ===
Line 28: Line 30:
       @HandleFire       @HandleFire
     endcase     endcase
 +    @HandleException # no case statement evaluated to TRUE
 endswitch endswitch
 </code> </code>
Line 41: Line 44:
       Trace ("Case 2 is valid"       Trace ("Case 2 is valid"
    endCase    endCase
 +   Trace("There is no case to be made")  
 endSwitch endSwitch
  
-Trace("There is no case to be made") 
 </code> </code>
  
4rpl/commands/switch.1662554478.txt.gz · Last modified: 2022/09/07 08:41 by Karsten75