DO CASE..ENDCASE

Control Structures – Decision making; DO CASE..ENDCASE

Do Case

/*

Control Structures - Decision making; DO CASE..ENDCASE

For more information refer here 

*/

PROCEDURE Main()
   CLS

   nKey := 0

   cDash := ''

   ? "Press a digit key ( Esc for exit ) : " 

   DO WHILE nKey # 27

      nKey := INKEY( 0 )

      IF nKey > 47 .AND. nKey < 58 

         ?? cDash

         DO CASE
            CASE nKey = 48
               ?? "zero"
            CASE nKey = 49
               ?? "one"
            CASE nKey = 50
               ?? "two"
            CASE nKey = 51
               ?? "three"
            CASE nKey = 52
               ?? "four"
            CASE nKey = 53
               ?? "five"
            CASE nKey = 54
               ?? "six"
            CASE nKey = 55
               ?? "seven"
            CASE nKey = 56
               ?? "eight"
            CASE nKey = 57
               ?? "nine"
         ENDCASE

         cDash := '-'

      ENDIF nKey > 47 .AND. nKey > 58 

   ENDDO

RETURN // Main()