0% found this document useful (0 votes)
75 views1 page

Rust Infinite Loop Explained

The document discusses Rust's loop keyword which indicates an infinite loop. The break statement can exit a loop and continue skips the rest of an iteration and starts a new one. An example shows counting to infinity using loop, continue, and break.

Uploaded by

Vladimír Pilát
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
75 views1 page

Rust Infinite Loop Explained

The document discusses Rust's loop keyword which indicates an infinite loop. The break statement can exit a loop and continue skips the rest of an iteration and starts a new one. An example shows counting to infinity using loop, continue, and break.

Uploaded by

Vladimír Pilát
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

loop - Rust By Example 09.10.

2023 13:04

loop
Rust provides a loop keyword to indicate an infinite loop.

The break statement can be used to exit a loop at anytime, whereas the continue
statement can be used to skip the rest of the iteration and start a new one.

1 fn main() {
2 let mut count = 0u32;
3
4 println!("Let's count until infinity!");
5
6 // Infinite loop
7 loop {
8 count += 1;
9
10 if count == 3 {
11 println!("three");
12
13 // Skip the rest of this iteration
14 continue;
15 }
16
17 println!("{}", count);
18
19 if count == 5 {
20 println!("OK, that's enough");
21
22 // Exit this loop
23 break;
24 }
25 }
26 }

[Link] Stránka 1 z 1

You might also like