Difference between revisions of "For"

From MiniScript Wiki
Jump to navigation Jump to search
m
(Created an example for iterating over a range of numbers and an example of iterating over a list.)
Line 4: Line 4:
 
[[Category:Keywords]]
 
[[Category:Keywords]]
  
{{stub}}
+
== Example ==
 +
Iterate over a range of numbers
 +
<ms>
 +
for i in range(1,10)
 +
    print i
 +
end for
 +
</ms>
 +
 
 +
== Example ==
 +
Iterate over a list
 +
<ms>
 +
words = ["hello", "MiniScript", "wiki"]
 +
for word in words
 +
    print word
 +
end for
 +
</ms>

Revision as of 01:06, 8 May 2022

for is a keyword used to loop over a sequence (i.e. a list, map, or string).

Example

Iterate over a range of numbers

for i in range(1,10)
    print i
end for

Example

Iterate over a list

words = ["hello", "MiniScript", "wiki"]
for word in words
    print word
end for