How to resolve the algorithm Conditional structures step by step in the langur programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Conditional structures step by step in the langur programming language

Table of Contents

Problem Statement

List the conditional structures offered by a programming language. See Wikipedia: conditionals for descriptions. Common conditional structures include if-then-else and switch. Less common are arithmetic if, ternary operator and Hash-based conditionals. Arithmetic if allows tight control over computed gotos, which optimizers have a hard time to figure out.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Conditional structures step by step in the langur programming language

Source code in the langur programming language

if .x == 0 {
    ...
} else if .x > 0 {
    val .y = 100
    ...
} else {
    val .y = 70
    ...
}

if(.x > .y: ...; .x < .y: ...; /* else */ ...)

if .x > .y: break

switch .x, .y, .z {
    case true: ...
        # any are true
    case false, _: ...                  
        # .x == false
    case _, null, true: ...
        # .y == null or .z == true
    case xor _, true, true: ...
        # .y == true xor .z == true
}

switch 0 {
    case .x, .y: ...
        # .x or .y equals 0
    ...
}

given .x, .y, .z {
    case true: ...
        # all are true
    case false, _: ...                  
        # .x == false
    case _, null, true: ...
        # .y == null and .z == true
}

given .x {
    case true:     
        # implicit fallthrough
    case null: 0
        # no fallthrough
    default: 1
}

given .x {
    case true:
        if .y > 100 {
            fallthrough
        } else {
            120
        }
    case false: ...
}

given(.x, .y, .z;
    true: ... ;     # all are equal to true
    _, >= .z: ...;  # .y >= .z
    ... )           # default

  

You may also check:How to resolve the algorithm Kernighans large earthquake problem step by step in the Nim programming language
You may also check:How to resolve the algorithm Hello world/Newbie step by step in the Robotic programming language
You may also check:How to resolve the algorithm Integer overflow step by step in the AutoHotkey programming language
You may also check:How to resolve the algorithm Sorting algorithms/Merge sort step by step in the REXX programming language
You may also check:How to resolve the algorithm Pascal's triangle/Puzzle step by step in the PARI/GP programming language