Wu Language
Search…
Getting Started
Writing code
Declarations
Optionals
If and While
For
Switch
Functions
Structs
Module
Traits
Powered By
GitBook
For
In Wu there are two different ways to use for loops. The first one is very simple:
1
for
100
{
2
print
(
"ONE HUNDRED TIMES!!!"
)
3
}
Copied!
Simply using a single integer, you can repeat a certain code block a given amount of times.
The second way to use a for loop is using iterators. In the following snippet, we use the
range
built-in iterator:
1
for
i
in
range
(
0
,
100
)
{
2
print
(
"road to one hunnid: "
,
i
)
3
}
Copied!
Of course, enumerating iterators also exist:
1
numbers
:=
[
1
,
2
,
3
,
4
,
5
]
2
3
for
i
,
v
in
ipairs
(
numbers
)
{
4
print
(
i
,
v
)
5
}
Copied!
Or simply iterating a list:
1
names
:=
[
"bob"
,
"niels"
,
"kaj"
]
2
3
for
v
in
iter
(
names
)
{
4
print
(
"name: "
++
name
)
5
}
Copied!
Previous
If and While
Next
Switch
Last modified
2yr ago
Copy link