Control Flow: if, while, loop, and for
C programmers usually start with this mapping:
C if -> Rust if
C while -> Rust while
C for -> Rust for
C break -> Rust break
C continue -> Rust continue
The mapping is mostly right, but a few differences affect everyday code:
ifandwhileconditions must beboolifcan produce a value- Rust has no C-style
for (init; condition; step) - Rust
foriterates over an iterable value loopexpresses an intentional infinite loop and can return a value withbreak value
These are not advanced features. They show up immediately in CLI tools and buffer processing.
Read More