Skip to content

Commit

Permalink
add branches and loops file
Browse files Browse the repository at this point in the history
  • Loading branch information
AlphonseMehounme committed Nov 27, 2024
1 parent 789ff7c commit fab81b8
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Rust/branches.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
fn main() {
let condition = false;

let number = if condition { 5 } else { 4 };

if number % 4 == 0 {
println!("number is divisible by 4");
} else if number % 3 == 0 {
println!("number is divisible by 3");
} else if number % 2 == 0 {
println!("number is divisible by 2");
} else {
println!("number is not divisible by 4, 3 or 2");
}
}
41 changes: 41 additions & 0 deletions Rust/loops.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
fn main() {
println!("----Start----");
let mut counter = 0;
let result = loop {
counter += 1;
println!("counter is {counter}");
if counter == 10 {
break counter * 2;
}
};
println!("The result is {result}");

let mut count = 0;
'counting_up: loop {
println!("Count: {count}");
let mut remaining = 10;

loop {
println!("Remaining: {remaining}");
if remaining == 9 {
break;
}
if count == 2 {
break 'counting_up;
}
remaining -= 1;
}
count += 1;
}

while count != 0 {
println!("Not zero yet");
count -= 1;
}
let coins = ["BTC", "BTC", "BTC"];
for coin in coins {
println!("Thes best is {coin} and there is no second best");
}
println!("Count is now 0
----End----");
}

0 comments on commit fab81b8

Please sign in to comment.