Skip to content

Commit

Permalink
Add example of foreach by ref.
Browse files Browse the repository at this point in the history
  • Loading branch information
lerno committed Jul 27, 2024
1 parent 028c9ce commit 963707e
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/content/docs/references/docs/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,29 @@ fn void example_for()

#### foreach-loop
```c3
// Prints the values in the slice.
fn void example_foreach(float[] values)
{
foreach (index, value : values)
{
io::printfn("%d: %f", index, value);
}
}
// Updates each value in the slice
// by multiplying it by 2.
fn void example_foreach_by_ref(float[] values)
{
foreach (&value : values)
{
*value *= 2;
}
}
```




#### while-loop

```c3
Expand Down

0 comments on commit 963707e

Please sign in to comment.