Rust contains loop
, which is specially designed for infinite looping:
Using the keyword
loop
,Rust
provides a way to loop indefinitely until some terminating statement is reached (like program exit)
I can't think of a single scenario when I would like my loops to run forever. Are there any scenarios when an infinite loop can be useful?
The main loop in embedded programs. Embedded devices often expect to run for as long as they are switched on. The two main pieces of code are usually event handlers and the main loop. If there is a main loop, it runs forever.
The main loop may have a "wait for interrupt" or it may just constantly dedicate its CPU resources to figuring out a better way to achieve its goal.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With