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
  • Sample Code to iterate over list using foreach
  • Sample code ot iterate over string using foreach
  1. Loops in SRON

Foreach Loop

'foreach' is a looping attribute which is used to linearly iterate over String or List type values.

SRON provides 'foreach' attribute to work on foreach loop. To provide the value and the variable, 'on' attribue is used.

Syntax of 'on':

on : variable_name , value_to_iterate_on

Examples:

Correct Syntax:
    on : (Any val, [1,2,3,4])
or
    on : (val, "Saksham Rapid Object Notation")

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

Wrong Syntax:
    @ 'on' attribute expects a String or List type of value
    on : val, 1234
or
    @ 'on' attribute doesn't require one variable and one value
    on : ("SRON")

Sample Code to iterate over list using foreach

{
    name : Main
    Any value = [1, 2, 3, true, Void, [91, 92, 93]]
    foreach : {
        on : (Any i, value)
        println(i)
    }
}

OUTPUT :

0 1 2 3 true <#-Void-#> [91, 92, 93]


Sample code ot iterate over string using foreach

{
    name : Main
    foreach : {
        on : (Any i , "SRON")
        println(i)
    }
}

OUTPUT :

S R O N


PreviousWhile LoopNextBreak & Continue

Last updated 6 months ago