pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: https://doc.rust-lang.org/std/iter/../clone/../hash/../../std/keyword.while.html

fe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>``).join(""))

while

Keyword while 

Source
Expand description

Loop while a condition is upheld.

A while expression is used for predicate loops. The while expression runs the conditional expression before running the loop body, then runs the loop body if the conditional expression evaluates to true, or exits the loop otherwise.

let mut counter = 0;

while counter < 10 {
    println!("{counter}");
    counter += 1;
}

Like the for expression, we can use break and continue. A while expression cannot break with a value and always evaluates to () unlike loop.

let mut i = 1;

while i < 100 {
    i *= 2;
    if i == 64 {
        break; // Exit when `i` is 64.
    }
}

As if expressions have their pattern matching variant in if let, so too do while expressions with while let. The while let expression matches the pattern against the expression, then runs the loop body if pattern matching succeeds, or exits the loop otherwise. We can use break and continue in while let expressions just like in while.

let mut counter = Some(0);

while let Some(i) = counter {
    if i == 10 {
        counter = None;
    } else {
        println!("{i}");
        counter = Some (i + 1);
    }
}

For more information on while and loops in general, see the reference.

See also, for, loop.

pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy