update
This commit is contained in:
parent
68cc0a4a34
commit
b911a95873
6 changed files with 30 additions and 6 deletions
|
@ -107,6 +107,31 @@ while condition {
|
|||
}
|
||||
```
|
||||
|
||||
You can break out of a loop or continue to the next iteration:
|
||||
```rust
|
||||
for i in 0..10 {
|
||||
if i % 2 == 0 {
|
||||
continue
|
||||
}
|
||||
if i % 5 == 0 {
|
||||
break;
|
||||
}
|
||||
println!("{i}");
|
||||
}
|
||||
```
|
||||
|
||||
If you have nested loops you can label them and use `break` and `continue` on specific loops:
|
||||
```rust
|
||||
'outer_loop: for i in 0..10 {
|
||||
'inner_loop: for x in 0..10 {
|
||||
if (x*i) > 40 {
|
||||
continue 'outer_loop;
|
||||
}
|
||||
print("{x} {i}");
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Functions
|
||||
One can use functions with optional arguments and return types. If you `return` on the last line, you can ommit the `return` keyword and `;` to return the value.
|
||||
```rust
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue