Skip to main content

03-some example

Lilya 黑静美Original...Less than 1 minuteprogramrustsyntax

fn main() {
 // Program entry point
 let mut n = 6; // Mutable variable binding
 print!("{n}"); // Macro for printing, like printf
 while n != 1 {
 // No parenthesis around expression
 if n % 2 == 0 { // n modulo 2
 n /= 2; // divide by 2
 } else {
 n = 3 * n + 1;
 }
 print!(" -> {n});
 }
 println!();
}
Last update:
Contributors: Heijingmei
Comments
  • Latest
  • Oldest
  • Hottest
Powered by Waline v3.1.3