Documentations - SRON
  • SRON's Official Documentation
  • Installation
  • Syntax of SRON
  • Executing a SRON code
  • Keywords in SRON
  • Comments in SRON
  • Datatypes in SRON
  • Variables in SRON
  • Memory Ownership Model
  • Operators in SRON
  • Math block
  • if elif else in SRON
  • Loops in SRON
    • For Loop
    • While Loop
    • Foreach Loop
  • Break & Continue
  • Functions in SRON
    • Print functions
    • User Input Functions
    • Type Conversion functions
    • Type Checking functions
    • Math functions
    • Char Functions
    • String Functions
    • List Functions
    • Miscellaneous functions
  • Return in SRON
  • Command Line Arguments
  • Free
  • Rotate
  • Console
  • Sample codes
  • Coding Convention
  • Frequently Asked Questions
  • Credits
  • Contact
  • Donate
Powered by GitBook
On this page

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")
    }
}

PreviousMath blockNextLoops in SRON

Last updated 6 months ago