switch Statement

The switch statement selects a block of code to execute based on the value of an expression.

switch expression do
    case value1:
        # body
    case value2, value3:
        # body
    default:
        # body
end

Syntax Rules

  • The do keyword follows the switch expression
  • Multiple values per case are comma-separated
  • The colon after case values is optional
  • The default clause is optional and handles unmatched values
  • The block is closed with end

No Fall-Through

Only the matched case executes. There is no fall-through between cases, and no break is needed.

switch Data.action do
    case "create":
        Data.status = "created"
    case "update", "patch":
        Data.status = "updated"
    default:
        Data.status = "unknown"
end

In this example, if Data.action is "update" or "patch", only the second case body executes. The default case is skipped.


Back to top

Copyright © Mesch Systems 2025-2026. All rights reserved.