Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!
:timing
:sccache 1loop¶
let mut count = 0;
loop {
println!("{}", count);
count += 1;
if count >= 5 {
break;
}
}0
1
2
3
4
()while loop¶
let mut count = 0;
while count < 5 {
println!("{}", count);
count += 1;
}0
1
2
3
4
()let mut count = 0;
while true {
println!("{}", count);
count += 1;
if count >= 5 {
break;
}
}0
1
2
3
4
()for loop¶
for word in "how are you".split_whitespace() {
println!("{}", word);
}how
are
you
()for i in 1..5 {
println!("{}", i);
}1
2
3
4
()fn print_type_of<T>(_: &T) {
println!("{}", std::any::type_name::<T>())
}let names: Vec<&str> = vec!["Pascal", "Elvira", "Dominic", "Christoph"];
for name in names {
println!("{}", name);
}Pascal
Elvira
Dominic
Christoph
()let names = vec!["Pascal", "Elvira", "Dominic", "Christoph"];
for name in &names {
println!("{}", name);
print_type_of(name);
}Pascal
&str
Elvira
&str
Dominic
&str
Christoph
&str
()