Search⌘ K
AI Features

Indefinite Loop - While and Loop

Explore how to implement indefinite loops in Rust using while and loop keywords. Learn to control iterations with conditions, manage mutable variables inside loops, and understand infinite loops for ongoing processes.

While loop

While loop also iterates until a specific condition is reached. However, in the case of a while loop, the number of iterations is not known in advance.

Syntax

The while keyword is followed by a condition that must be true for the loop to continue iterating and then begins the body of the loop.

The general syntax is :

Example

The following example makes use of a while loop to print a variable value. The ...