Code Example Template
for key in keyboard_layout.keys() {
    render(item);
}

Deep-Dive System Documentation

Loops and Sequence Iterators

Rust offers three main constructs to repeat code execution:

1. loop (Infinite)

An infinite loop. Renders the compiler aware that the loop will only cease if break is explicitly called. You can return values directly from a loop using break value;.

let mut counter = 0;
let result = loop {
    counter += 1;
    if counter == 10 {
        break counter * 2; // returns 20
    }
};

2. while (Conditional)

Executes a block while a condition remains true.

while is_listening() {
    process_events();
}

3. for (Iterators)

Loops through elements of any collection implementing IntoIterator. It is zero-cost compared to manual index looping, preventing off-by-one errors completely.

for key in 0..=5 {
    press_key(key);
}

Quick Reference Guide

for i in 0..10 { /* ... */ }
loop { if done { break; } }