murex Shell Docs

Command Reference: switch

Blocks of cascading conditionals

Description

switch is a large block for simplifying cascades of conditional statements.

Usage

switch {
  case | if { conditional } then { code-block }
  case | if { conditional } then { code-block }
  ...
  [ catch { code-block } ]
} -> <stdout>

Examples

Output an array of editors installed

switch {
  if { which: vim   } { out: vim   }
  if { which: vi    } { out: vi    }
  if { which: nano  } { out: nano  }
  if { which: emacs } { out: emacs }
} -> format: json

function higherlower {
  try {
    rand: int 100 -> set rand
    while { $rand } {
      read: guess "Guess a number between 1 and 100: "

      switch {
        case: { = $guess < $rand } then {
          out: "Too low"
        }

        case: { = $guess > $rand } then {
          out: "Too high"
        }

        catch: {
          out: "Correct"
          let: rand=0
        }
      }
    }
  }
}

See Also

This site is rebuilt weekly, the content is automatically generated from murex's source code. Last built on Mon Aug 3 06:12:53 UTC 2020 against commit 2557f7c2557f7cc7535c452c21d89164bd38ed8996f02fd. Downloadable murex binaries are also built weekly. Current version is 0.52.2000 BETA which has been verified against tests.