if elif else in SRON

SRON provides if, elif and else attributes to take logical decision based upon certain conditions.

If and elif executes the statements only when a certain condition is true. SRON provides 'if', 'elif' and 'else' attributes for this.

If neither if's condition is true nor elif's, then else statements runs.

To provide the condition on the basis of which if or elif take decisions, 'condition' attribute is used.

A sample code to check if a number is even or odd.

{
    name : MAIN
    Int x = 20
    
    if : {
        condition : ~{ x % 2 == 0 }~
        println("Even")
    }
    else : {
        println("Odd")
    }
}
A sample code to check if a number is divisible by either 2 or 3.

{
    name : MAIN
    Int x = 15

    if : {
        condition :~{ % 2 == 0 }~
        println("Divisible by 2")
    }
    elif : {
        condition : ~{ x % 3 == 0 }~
        println("Divisible by 3")
    }
    else : {
        println("Not Divisible by both 2 and 3")
    }
}

Last updated