Loops

Katton does not have a while loop

ascending ranges: 0..9

for (i in 0..9) {
    Katton.log.info("round " + i)
}
// prints round 0, round 1, ... round 9 

0..9 includes both 0 and 9, nine rounds total would actually be 0..8 or 1..9.

descending ranges: 10 downTo 1

for (i in 10 downTo 1) {
    Katton.log.info("" + i)
}
// prints 10, 9, 8, ... 1

iterating a list

val colors = ["red", "blue", "lime"]

for (color in colors) {
    Katton.log.info("Color: " + color)
}

iterating a map (iterates keys)

val scores = { "red": 1, "blue": 2 }

for (team in scores) {
    Katton.log.info(team + " has " + scores[team] + " points")
}

iterating players

for (player in Katton.players.all()) {
    player.sendMessage("&around starting!")
}

break and continue

for (i in 0..100) {
    if (i == 50) {
        break // stops the loop entirely
    }
    if (i % 2 == 0) {
        continue // skips to the next iteration
    }
    Katton.log.info("odd number: " + i)
}