Control Structures

The control structures of SPLASH are similar to those in C and Java.

Use the if and switch statements for conditional execution. For example, this block sets a string variable to different values depending on the sign of the temperature:
if (temperature < 0) {
  display := 'below zero';
} else if (temperature = 0) {
  display := 'zero';
} else {
  display := 'above zero';
}
The switch statement selects from a number of alternatives:
switch (countryCode) {
  case 1: 
    continent := 'North America';
    break;
  case 33:
  case 44:
  case 49:
    continent := 'Europe';
    break;
  default:
    continent := 'Unknown';
}
The expression after the switch can be an integer, long, money, money(n), float, date, timestamp, or bigdatetime.
The while statement encodes loops. For example, this computes the sum of the squares of 0 through 9:
integer i := 0, squares := 0;
while (i < 10) {
  squares := squares + (i * i);
  i++;
}
This example uses the operator ++ to add 1 to the variable i. The break statement exits the loop, and continue starts the loop again at the top.

Finally, you can stop the execution of a block of SPLASH code with the exit statement. This statement doesn't stop the Event Stream Processor, just the block.