sample-code: Add some sample Conlang programs :D
This commit is contained in:
20
sample-code/fizzbuzz.cl
Normal file
20
sample-code/fizzbuzz.cl
Normal file
@@ -0,0 +1,20 @@
|
||||
// FizzBuzz, using the unstable variadic-`print` builtin
|
||||
|
||||
fn main() {
|
||||
fizz_buzz(10, 20)
|
||||
}
|
||||
|
||||
// Outputs FizzBuzz for numbers between `start` and `end`, inclusive
|
||||
fn fizz_buzz(start: i128, end: i128) {
|
||||
for x in start..=end {
|
||||
print(if x % 15 == 0 {
|
||||
"FizzBuzz"
|
||||
} else if 0 == x % 3 {
|
||||
"Fizz"
|
||||
} else if x % 5 == 0 {
|
||||
"Buzz"
|
||||
} else {
|
||||
x
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user