Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

    1. The switch statement is an enhanced version of the if statement. Its syntax is the following:

      Code Block
      switch (key1) {
          case val1:
              # statements
          case val2:
              # statements
          default:
              # 
      }
      

      The value of the key given as argument to the switch statement is matched against the values specified in the case statements. If there is a match, then the statements corresponding to the matching case statement are executed. Otherwise, the default case is executed. The default case is mandatory if the case statements do not cover all the possibilities. The "~" operator can be used to match "anything". Following is an example showing the use of the switch statement:

      Code Block
      print 'processing paramId=[paramId] [shortName] [stepType]';
      switch (shortName) {
          case 'tp' :
              set stepType='accum';
              print 'Message #[count]: Total Precipitation';
          case '10u' :
              set typeOfLevel='surface';
              print 'Message #[count]: 10m U-Wind';
          default:
      }