Add recursive countdown example in Rust
This commit is contained in:
10
03_recursion/rust/01_countdown/.gitignore
vendored
Normal file
10
03_recursion/rust/01_countdown/.gitignore
vendored
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
# Generated by Cargo
|
||||||
|
# will have compiled files and executables
|
||||||
|
/target/
|
||||||
|
|
||||||
|
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
|
||||||
|
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
|
||||||
|
Cargo.lock
|
||||||
|
|
||||||
|
# These are backup files generated by rustfmt
|
||||||
|
**/*.rs.bk
|
||||||
9
03_recursion/rust/01_countdown/Cargo.toml
Normal file
9
03_recursion/rust/01_countdown/Cargo.toml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
[package]
|
||||||
|
name = "countdown"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["Alexander Launi <alex.launi@gmail.com>"]
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
12
03_recursion/rust/01_countdown/src/main.rs
Normal file
12
03_recursion/rust/01_countdown/src/main.rs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
fn countdown(i: u32) {
|
||||||
|
println!("{}", i);
|
||||||
|
if i == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
countdown(i - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
countdown(5);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user