Switch: Difference between revisions

From EDukeWiki
Jump to navigation Jump to search
No edit summary
Remove misleading information
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
The '''switch''' statement in con is similar to that in C.
The '''switch''' statement in CON is similar to that in C.


   switch <gamevar>
   switch <gamevar>
     case <constant>
     case <constant>
       <do something>
       <do something>
      [[break]]
    break
     case <constant>
     case <constant>
       <do something>
       <do something>
       break
    break
   [[endswitch]]
    default
       <do something>
    break
   endswitch


Caution:  ''Nested switches do not work because of the way the CON compiler compiles them''. A workaround is to put the nested switch in a seperate state, and call that state from inside the first switch.
The '''case''' keyword works like an [[ifvare]] statement, and '''default''' operates on every possibility that is ''not'' specified by a case statement. Each case block must be terminated with a '''[[break]]''' statement.


Also, putting extra [[break]] statements inside a case argument will cause a lot of errors. Again, the workaround is to put the commands that need to be seperated in another state, along with the break.
See: [http://www.cplusplus.com/doc/tutorial/control/ Control Structures @ C++ Documentation]


[[Category:EDuke commands]]
[[Category:EDuke commands]]

Latest revision as of 00:16, 12 September 2021

The switch statement in CON is similar to that in C.

 switch <gamevar>
   case <constant>
     <do something>
   break
   case <constant>
     <do something>
   break
   default
     <do something>
   break
 endswitch

The case keyword works like an ifvare statement, and default operates on every possibility that is not specified by a case statement. Each case block must be terminated with a break statement.

See: Control Structures @ C++ Documentation