Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Level 14. Repeating Things

Sometimes you want to do something more than once. Hica has repeat for that:

fun main() {
  repeat(5) {
    println("hica!")
  }
}

This prints hica! five times. The number in parentheses is how many times the block runs.

You can use any expression for the count:

fun main() {
  let times = 3
  repeat(times) {
    println("go!")
  }
}

🎯 Try it: What happens if you use repeat(0)? What about repeat(1)?