Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Semrush - keyword research tool

Turn ChatGPT, Claude, Gemini, And CoPilot Into Your Personal Assistant, Business Coach, Content Creator, And More

AFFILIATE MARKETING Your all-in-one performance engine Manage affiliates, creators, and customer referrals in one unified platform—turning every partnership into measurable growth
Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

42,683 questions

55,435 answers

573 users

How to create an infinite loop in Rust

3 Answers

0 votes
fn main() {
    let mut count = 0u16;
 
    loop { // infinite loop
        count += 1;
 
        if count == 4 {
            println!("count == 4");
            continue;
        }
 
        println!("{}", count);
 
        if count == 7 {
            println!("count == 7 -> break");
            break;
        }
    }
}

 
 
/*
run:
 
1
2
3
count == 4
5
6
7
count == 7 -> break
 
*/

 



answered May 4, 2023 by avibootz
edited Apr 10 by avibootz
0 votes
fn main() {
    let mut count = 0u16;
 
    while true { // infinite loop
        count += 1;
 
        if count == 4 {
            println!("count == 4");
            continue;
        }
 
        println!("{}", count);
 
        if count == 7 {
            println!("count == 7 -> break");
            break;
        }
    }
}

 
/*
run:
 
1
2
3
count == 4
5
6
7
count == 7 -> break
 
*/

 



answered Apr 10 by avibootz
0 votes
fn main() {
    let mut i = 0;
    let mut count = 0u16;
 
    // Infinite loop with a condition that never changes
    while i >= 0 {
        println!("i = {}", i);
        i += 1;
        
        count += 1;
 
        if count == 4 {
            println!("count == 4");
            continue;
        }
 
        println!("{}", count);
 
        if count == 7 {
            println!("count == 7 -> break");
            break;
        }
    }
}

 
/*
run:
 
i = 0
1
i = 1
2
i = 2
3
i = 3
count == 4
i = 4
5
i = 5
6
i = 6
7
count == 7 -> break
 
*/

 



answered Apr 10 by avibootz
...