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
  1. Loops in SRON

While Loop

'while' is a looping attribute which is used to perform a set of instructions until a given condition is satisfied.

SRON provides 'while' attribute to work on while loop. To provide a condition, 'condition' attribute is used.

Syntax of 'condition':

condition :  condition_value

Examples:

Correct Syntax:
    condition : false
or
    condition : ~{ val != 10 }~

---------------------

Wrong Syntax:
    condition : ()
or
    condition : (true)
or
    condition : ([1,2,3,4,5])

'condition' attribute requires a 'Bool' type value, if a 'Bool' type value is not found, then error/exception will be thrown.


Sample Code to print 0 to 5 numbers.

{
    name : MAIN

    Int i

    while : {
        condition : ~{ i < 6 }~

        println(i)

        i += 1
    }
}

OUTPUT :

0 1 2 3 4 5


Sample Code to print even number between 0 and 15.

{
    name : MAIN

    Int i = 2

    while : {
        condition : ~{ i < 15 }~

        if : {
            condition : ~{ i % 2 == 0 }~
            print(i, ' ')
        }
        
        i += 1
    }
}

OUTPUT :

2 4 6 8 10 12 14


PreviousFor LoopNextForeach Loop

Last updated 6 months ago