functions, loops and control flow

This commit is contained in:
2025-12-20 18:13:04 +00:00
parent 83fc3600b8
commit 04c6e7e66a
12 changed files with 300 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
[package]
name = "christmas"
version = "0.1.0"
edition = "2024"
[dependencies]

View File

@@ -0,0 +1,42 @@
//this probably can be made better
fn main() {
let cardinals: [&str; 12] = [
"first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "ninth",
"tenth", "eleventh", "twelfth",
];
let lines: [&str; 12] = [
"A partridge in a pear tree",
"Two turtle doves",
"Three French hens",
"Four colly birds",
"Five gold rings",
"Six geese a-laying",
"Seven swans a-swimming",
"Eight maids a-milking",
"Nine drummers drumming",
"Ten pipers piping",
"Eleven ladies dancing",
"Twelve fiddlers fiddling",
];
for mut i in 1..13 {
println!("The {} day of Christmas,", cardinals[i - 1]);
println!("My true love sent to me");
while i != 0 {
while i != 0 {
if i == 1 {
println!("{}.\n", lines[i - 1]);
} else {
if i == 2 {
println!("{}, and", lines[i - 1]);
} else {
println!("{},", lines[i - 1]);
}
}
i -= 1;
}
}
}
}