punto y coma
This commit is contained in:
@@ -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)
|
||||
|
||||
8
ejemplo02/Cargo.toml
Normal file
8
ejemplo02/Cargo.toml
Normal file
@@ -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]
|
||||
22
ejemplo02/src/main.rs
Normal file
22
ejemplo02/src/main.rs
Normal file
@@ -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);
|
||||
}
|
||||
Reference in New Issue
Block a user