nombre y arreglos2

This commit is contained in:
2023-06-08 18:43:55 +02:00
parent 07d62f050e
commit 6e1cd4e0fc
6 changed files with 51 additions and 8 deletions

View File

@@ -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)
- 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)

8
arreglos2/Cargo.toml Normal file
View File

@@ -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]

12
arreglos2/src/main.rs Normal file
View File

@@ -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;
}
}

8
nombre/Cargo.toml Normal file
View File

@@ -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]

13
nombre/src/main.rs Normal file
View File

@@ -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);
}
}
}

View File

@@ -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)
}
let pos = primera_palabra(&s);
let palabra = &s[0..pos];
println!("{}", palabra);
}