loop
is often used for loops where we want to break in the middle of the loop's body. That is, you want to do something before testing any condition, then exit the loop if some condition is met, then do something else that must only be done after testing the condition, then repeat. In other languages, this is often rendered as while (true)
or for (;;)
. This situation is common enough that Rust decided to embrace this pattern by reserving a keyword to declare loops that have no entry condition.
Also, Rust doesn't have the equivalent of C's do..while
loop, which tests a condition at the end of an iteration, but not before the first iteration. In Rust, you'd emulate it with a loop
and an if condition { break }
statement at the end of the loop. do..while
loops are relatively rare in practice, rarer than "break in the middle" loops in my experience.