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' attribute 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)
console : ( i , '\n' )
}
}
OUTPUT :
0 1 2 3 true <#-Void-#> [91, 92, 93]
Sample code to iterate over string using foreach
{
name : Main
foreach : {
on : (Any i , "SRON")
console : ( i )
}
}
OUTPUT :
S R O N
Last updated