Case statement

The EGL case statement responds to conditions at run time by executing one set of statements rather than another. The behavior is similar to that of a switch statement in Java or C.
The case statement has two forms, each of which includes one or more when clauses and an optional otherwise clause:

In either case, the otherwise clause, if any, executes only if no other clause executes.

At most, one clause executes; control does not “fall through” from one clause to the next.

After the case statement completes its run, processing continues at the statement after the case statement, unless an embedded continue statement transfers control to a label that resides elsewhere in the function.

Syntax



Syntax diagram for the case statement

criterion
A value that is compared against the matchExp values in subsequent when clauses. The case statement runs the first clause in which the criterion value matches the matchExpvalue.
label
A label that is attached to an enclosing for, forEach, or while statement. Processing continues with the referenced statement.
logicalExpr
A logical expression that, if true, causes the invocation of the related set of statements. The case statement runs the first clause for which the logical expression is true.
matchExpr
A value for comparison with the criterion value.
statement
An EGL statement.
The following case statement includes multiple match expressions in the second when clause (2, 3, 4):
  case (myRecord.requestID)
    when (1)
      myFirstFunction();
    when (2, 3, 4)
      try
        call myProgram;
      onException(iex InvocationException)
        myCallFunction(fileEx);
      end
    otherwise
      myDefaultFunction();
  end  
After the following case statement runs, the standard output displays only the message “x passes”:
Program calc3
  x INT = 3;
  y INT = 5;
  z INT = 7;
  function main()
    case
      when (x == 3)
        SysLib.writeStdOut("x passes");
      when (y == 5)
        SysLib.writeStdOut("y passes");
      when (z == 7)
        SysLib.writeStdOut("z passes");
      otherwise
        SysLib.writeStdErr("You should not see this msg");
    end
  end

Compatibility

Table 1. Compatibility
Target Issue
Java No issues
JavaScript No issues.