Scriptol/For In

From Wikibooks, open books for an open world
Jump to navigation Jump to search

For In[edit | edit source]

Common syntax[edit | edit source]

The standard syntax assigns a variable with the elements of a range, and Scriptol writes a range as it is commonly written, with a double dot between two values (or variables).

for int x in 0 .. 10
  print x

One-line syntax[edit | edit source]

If the body of the structure is only one statement, a simplified syntax is used.

for int x in 0 .. 10 print x 

For in list[edit | edit source]

The for control structure may scan an interal as above, but also a text or an array.

text hello = "hello"
for text t in hello print t 

array a = { 1, 2, 3 }
for dyn x in a print x