Expressions and starting flow control in RBE

This commit is contained in:
Dan Buch 2023-09-26 06:43:22 -04:00
parent 505e04613f
commit 7204f08177
Signed by: meatballhat
GPG Key ID: A12F782281063434
7 changed files with 122 additions and 3 deletions

View File

@ -1,6 +1,6 @@
/*.d/*
*.d/out
*.d/**/out
expression
hello
primitives
variable_bindings
!/*.d/*.rs

View File

@ -0,0 +1,25 @@
#[allow(path_statements)]
#[allow(unused_must_use)]
fn main() {
let x = 5;
x;
x + 1;
15;
let x = 5u32;
let y = {
let x_squared = x * x;
let x_cube = x_squared * x;
x_cube + x_squared + x
};
let z = {
2 * x;
};
println!("x is {:?}", x);
println!("y is {:?}", y);
println!("z is {:?}", z);
}

View File

@ -0,0 +1,23 @@
fn main() {
let n = 5;
if n < 0 {
print!("{} is negative", n);
} else if n > 0 {
print!("{} is positive", n);
} else {
print!("{} is zero", n);
}
let big_n = if n < 10 && n > -10 {
println!(", and is a small number, increase net-fold");
10 * n
} else {
println!(", and is a big number, halve the number");
n / 2
};
println!("{} -> {}", n, big_n);
}

View File

@ -0,0 +1,18 @@
#![allow(unreachable_code)]
#![allow(unused_labels)]
fn main() {
'outer: loop {
println!("Entered the outer loop");
'inner: loop {
println!("Entered the inner loop");
break 'outer;
}
println!("This point will never be reached");
}
println!("Exited the outer loop");
}

View File

@ -0,0 +1,13 @@
fn main() {
let mut counter = 0;
let result = loop {
counter += 1;
if counter == 10 {
break counter * 2;
}
};
assert_eq!(result, 20);
}

View File

@ -0,0 +1,23 @@
fn main() {
let mut count = 0u32;
println!("Let's count until infinity!");
loop {
count += 1;
if count == 3 {
println!("three");
continue;
}
println!("{}", count);
if count == 5 {
println!("OK, that's enough");
break;
}
}
}

View File

@ -0,0 +1,17 @@
fn main() {
let mut n = 1;
while n < 101 {
if n % 15 == 0 {
println!("fizzbuzz");
} else if n % 3 == 0 {
println!("fizz");
} else if n % 5 == 0 {
println!("buzz");
} else {
println!("{}", n);
}
n += 1;
}
}