Skip to content

Control Flow

If / Else

wyn
var score = 85

if score >= 90 {
    println("A grade")
} else if score >= 80 {
    println("B grade")
} else {
    println("Try harder")
}

For Loops

Range

wyn
for i in 0..5 {
    println("Count: ${i}")
}

Over Arrays

wyn
var fruits = ["apple", "banana", "orange"]
for fruit in fruits {
    println("Fruit: ${fruit}")
}

Indexed Iteration

Access both the index and value with for i, v in arr:

wyn
var names = ["Alice", "Bob", "Charlie"]
for i, name in names {
    println(i.to_string() + ": " + name)
}
// 0: Alice
// 1: Bob
// 2: Charlie

While Loops

wyn
var count = 0
while count < 3 {
    println("Count: ${count}")
    count = count + 1
}

Break and Continue

wyn
for i in 0..100 {
    if i == 5 { break }
    if i % 2 == 0 { continue }
    println(i.to_string())
}

Try It

🐉 Playground
Press Run or Ctrl+Enter

See Also

MIT License