How to use loop and while true in the same way with Rust

2 Answers

0 votes
fn main() {
    let x;
    
    loop { x = 3; break; }
    
    println!("{}", x)
}



  
/*
run:
  
3
  
*/

 



answered Apr 27, 2023 by avibootz
0 votes
#![allow(while_true)]

fn main() {
    let mut x = 0;
    
    while true { x = 3; break; }
    
    println!("{}", x);
}



/*
run:
  
3
  
*/

 



answered Apr 27, 2023 by avibootz
...