• News:
    • 0.20a2
      • added SELECTED keyword
      • doesn't matter on order of CASE/DEFAULT/SELECTED keywords


  • Syntax:
      SELECT <exp>
      CASE <exp1>             // multiple CASEs can occur
        <statements1>
      CASE <exp2>
        <statements2>
      ...
      [ DEFAULT
        <statements> ]
      [ SELECTED
        <statements0> ]
      ENDSELECT [ <list> ]
    

    <exp> is a source expression which will be compared with each of <exp1> expressions. <exp1> can contain multiple expressions. (See below.) If atleast one of them will be the same as result of <exp>, <statements1> will be processed. If no, next CASE will be tested. If no CASE matched the <exp>, <statements> (after DEFAULT) will be processed. And if atleast one of CASEs was tested successfully, the <statements0> will be processed when finished.

  • Multiple expressions:
    Single expressions must be separated by a comma (,):
      CASE <a>,<b>; <statements>
    

    If <exp> equals to <a> or <b>, <statements> will be processed.

  • Arrays in expressions:
    <exp1> can contain also arrays, which are made with TO keyword:
      CASE <a> TO <b>; <statements>
    

    where <a> is bottom and <b> is top of the array. If <exp> fits to the array <statements> will be processed.

    NOTE: Both of the above can be ofcourse combined!

  • Returning values:
    Please take a look at the examples below, especially take a look at 'IS' keyword.

  • Examples:
      SELECT age
      CASE 0 TO 17
        PrintF('Young\n')
      CASE 18 TO 50
        PrintF('Adult\n')
      CASE 51 TO 120
        PrintF('Old\n')
      DEFAULT
        PrintF('What???\n')
      ENDSELECT
    
      name:=SELECT Person.ID
        CASE 1 IS 'Paul'
        CASE 2 IS 'Jenny'
        CASE 3 IS 'Peter'
        CASE 4 IS 'Mark'
        ENDSELECT 'unknown'
    

    Check these examples with several values, and be sure You will understand it.
      PROC main()
        DEF a,s[16]:STRING
      
        PrintF('Enter a number 1-10: \n')
        ReadEStr(stdout,s)
        a:=Val(s)
        SELECT a
        SELECTED;     PrintF('good selection!\n')
        DEFAULT;      PrintF('bad number!\n')
        CASE 1 TO 3;  PrintF('gimme more!\n')
        CASE 4 TO 6;  PrintF('average!\n')
        CASE 7 TO 9;  PrintF('that much?\n')
        CASE 10;      PrintF('too much...\n')
        ENDSELECT
      ENDPROC
      
      PROC main()
        DEF a,s[16]:STRING
        PrintF('Enter Your age 1-100: \n')
        ReadEStr(stdout,s)
        a:=Val(s)
        PrintF('You are \s.\n',
          SELECT a
          CASE  0 TO  3 IS 'small baby'
          CASE  4 TO  6 IS 'baby'
          CASE  7 TO 10 IS 'child'
          CASE 11 TO 19 IS 'teenager'
          CASE 20 TO 50 IS 'adult'
          CASE 51 TO 99 IS 'old'
          DEFAULT       IS 'not a human ;)'
          ENDSELECT)
      ENDPROC