diff --git a/README.md b/README.md index c01ad1a..fc17ce4 100644 --- a/README.md +++ b/README.md @@ -24,3 +24,4 @@ - https://tinchicus.com/2022/07/01/rust-loop-labels/ (nombre) - https://tinchicus.com/2022/07/04/rust-while/ (while) - https://tinchicus.com/2022/07/05/rust-funciones-recursivas/ (recursiva) +- https://tinchicus.com/2022/07/06/rust-punto-y-coma/ (ejemplo02) diff --git a/ejemplo02/Cargo.toml b/ejemplo02/Cargo.toml new file mode 100644 index 0000000..96dca12 --- /dev/null +++ b/ejemplo02/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "ejemplo02" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/ejemplo02/src/main.rs b/ejemplo02/src/main.rs new file mode 100644 index 0000000..b052d78 --- /dev/null +++ b/ejemplo02/src/main.rs @@ -0,0 +1,22 @@ +fn main() { + let x = 5u32; + + let y = { + let x_cuadrado = x * x; + let x_cubo = x_cuadrado * x; + x_cubo + x_cuadrado + x + }; + + // La variable z no tiene ningĂșn valor, no es devuelto por el punto y coma + let z = { + 2 * x; + }; + + // la variable h tiene el valor de 2*x por que es devuelta al no tener punto y coma. + let h = { 2 * x }; + + println!("x es {:?}", x); + println!("y es {:?}", y); + println!("z es {:?}", z); + println!("h es {:?}", h); +}