Syntax

Rust Loop Forever Syntax

In Rust, loop forever: loops until break — loop { break; }

Quick Answer

Syntax
loop { break; }
RustSyntax

Loop Forever

Code example
loop { break; }

Loops until break.

Learn More

How to loop forever in Rust

  1. Open your Rust file or editor.
  2. Copy the example, then replace its sample names and values for your code.

Rust Loop Forever Syntax

Use loop { break; }.

Related Syntax References

Frequently asked questions

What is the Rust syntax for loop forever?

Use this pattern: loop { break; }

Can I copy this Rust code example?

Yes. Use Copy code and adapt the example to your program.

Is this Rust syntax different on Mac or Windows?

No. The language syntax is the same across operating systems.

Official source · How we verify