Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Usability of infinite loop in Rust

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?

like image 828
Fusion Avatar asked Sep 11 '16 18:09

Fusion


1 Answers

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.

like image 121
Max Murphy Avatar answered Oct 10 '22 14:10

Max Murphy