2 ms·
Rust only really has one loop, it's named loop and it's an infinite loop (you break to leave it). So just as Rust's "for" is syntactic sugar, so is "while", it
by tialaramex 4y ago
Rust only really has one loop, it's named loop and it's an infinite loop (you break to leave it).
So just as Rust's "for" is syntactic sugar, so is "while", it will de-sugar into loop with an exit condition break at the start, since that's how while works in Rust.
But this sort of illustrates how limited your model is, you're assuming the way loops worked in some language you've more experience with, probably C, is just "how loops work" but it's a weird feature of one language invented decades before the present, but decades after the fundamentals. It's like fixating on how the brakes worked on the 1971 Ford Cortina. That's not "how car brakes work" it's just how the brakes worked on that particular model of car, a brand new BMW i4 and a Model T are both equally reasonable examples of "how car brakes work".