Skip to content
Kavachकवच

For Loop: Repeat n times

● Beginner2 min

To repeat a block a number of times without using the number, name it _.

fn main() {
    for _ in 0..3 {
        print("knock")
    }
}

The program ran and printed:

kavach run times.kav

knockknockknock
times.kav: Kavach code, then what running it prints

_ says "I don't need this value": it never becomes a variable, and a reader sees at once that the number itself doesn't matter.