Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Force 4.0 Reference - do case multiple conditional branch start http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 do case             Multiple conditional branch start
------------------------------------------------------------------------------
 Syntax
   do case
   [ case <condition> ]
      [ <code> ]
   [ otherwise ]
      [ <code> ]
   endcase

 Arguments
   None.

 Description
   The do case statement initiates a conditional branch structure.
   The structure consists of none to several case statements, an optional
   otherwise statement, and a concluding endcase statement.

   The do case structure is used when the evaluation of an expression needs
   to be tested against many values. In such cases nested if statements
   become rather cumbersome. Instead the do case construct provides a method
   to implement multiple conditional controls.

   In the do case statement each logical expression beginning with the
   first case is evaluated. When one of the logical expressions evaluates to
   true, the commands between that case statement and the following case
   statement are executed. If none of the logical expressions are true,
   then the code between the keywords otherwise and endcase are executed.
   if there is no otherwise clause, control drops out of the do case
   construct and the first command after endcase is executed.

   Note that while it is possible that more than one of the expressions may
   be true, only the first of those case blocks is executed.

 Example
   #define EXAMPLE_STATEMEN
   #include example.hdr

   proc DispMsg static
   param value uint uRow, value uint uCol, const char cText
   @ uRow, uCol ?? cText
   endproc
   
   proc Test_docase
   vardef
      _SLIST pList
      uint   n
      uint   uChoice
   enddef
   pList := pickinit()
   for n := 0 to 6
      pickadd( pList, __daynames[ n ] )
   next
   clear
   uChoice := pickdisp( pList, 8, 35, 14, 45 )
   do case
   case uChoice == 0
      @ 20, 0 ?? "You seemingly pressed Escape"
   case uChoice == 1
      @ 20, 0 ?? "You selected", pickstr( pList, uChoice )
   case uChoice == 2
      @ 20, 0 ?? "The", istr( uChoice ) + "nd day of week is", ;
         __daynames[ uChoice - 1 ]
   case uChoice == 3
      DispMsg( 20, 0, "Let's call a function" )
   otherwise
      @ 20, 0 ?? "The docs writer became tired at this point"
   endcase
   pickclear( pList )
   endproc

   proc main
   Test_docase()
   endproc

See Also: case endcase exit loop otherwise

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson