From 6e1cd4e0fc28601563446e7f62bfea99b3441bd5 Mon Sep 17 00:00:00 2001 From: Manuel Riquelme Date: Thu, 8 Jun 2023 18:43:55 +0200 Subject: [PATCH] nombre y arreglos2 --- README.md | 4 +++- arreglos2/Cargo.toml | 8 ++++++++ arreglos2/src/main.rs | 12 ++++++++++++ nombre/Cargo.toml | 8 ++++++++ nombre/src/main.rs | 13 +++++++++++++ slices/src/main.rs | 14 +++++++------- 6 files changed, 51 insertions(+), 8 deletions(-) create mode 100644 arreglos2/Cargo.toml create mode 100644 arreglos2/src/main.rs create mode 100644 nombre/Cargo.toml create mode 100644 nombre/src/main.rs diff --git a/README.md b/README.md index 9f1d9c0..5c6f992 100644 --- a/README.md +++ b/README.md @@ -19,4 +19,6 @@ - https://tinchicus.com/2022/06/24/rust-funciones-y-metodos/ (ejemplo01) - https://tinchicus.com/2022/06/27/rust-closures/ (cierre) - https://tinchicus.com/2022/06/28/rust-iteradores/ (iter) -- https://tinchicus.com/2022/06/29/rust-el-parametro-_/ (bucles2) \ No newline at end of file +- https://tinchicus.com/2022/06/29/rust-el-parametro-_/ (bucles2) +- https://tinchicus.com/2022/06/30/rust-loop-27/ (arreglos2) +- https://tinchicus.com/2022/07/01/rust-loop-labels/ (nombre) diff --git a/arreglos2/Cargo.toml b/arreglos2/Cargo.toml new file mode 100644 index 0000000..73240af --- /dev/null +++ b/arreglos2/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "arreglos2" +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/arreglos2/src/main.rs b/arreglos2/src/main.rs new file mode 100644 index 0000000..6c671b6 --- /dev/null +++ b/arreglos2/src/main.rs @@ -0,0 +1,12 @@ +fn main() { + let mi_arreglo = ["Lovecraft", "Poe", "Barker", "King"]; + let mut i = 0; + + loop { + if i >= mi_arreglo.len() { + break; + } + println!("{}", mi_arreglo[i]); + i = i + 1; + } +} diff --git a/nombre/Cargo.toml b/nombre/Cargo.toml new file mode 100644 index 0000000..cb2577f --- /dev/null +++ b/nombre/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "nombre" +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/nombre/src/main.rs b/nombre/src/main.rs new file mode 100644 index 0000000..760e569 --- /dev/null +++ b/nombre/src/main.rs @@ -0,0 +1,13 @@ +fn main() { + 'bucle_externo: for x in 0..10 { + 'bucle_interno: for y in 0..10 { + if x % 2 == 0 { + continue 'bucle_externo; + } + if y % 2 != 0 { + continue 'bucle_interno; + } + println!("X: {}, Y: {}", x, y); + } + } +} diff --git a/slices/src/main.rs b/slices/src/main.rs index 5160179..704fa93 100644 --- a/slices/src/main.rs +++ b/slices/src/main.rs @@ -1,8 +1,8 @@ fn primera_palabra(s: &String) -> usize { - let b=s.as_bytes(); - for (i,&item) in b.iter().enumerate() { + let b = s.as_bytes(); + for (i, &item) in b.iter().enumerate() { if item == b' ' { - return i + return i; } } s.len() @@ -10,7 +10,7 @@ fn primera_palabra(s: &String) -> usize { fn main() { let s = String::from("Hola Mundo Cruel"); - let pos=primera_palabra(&s); - let palabra=&s[0..pos]; - println!("{}",palabra) -} \ No newline at end of file + let pos = primera_palabra(&s); + let palabra = &s[0..pos]; + println!("{}", palabra); +}