Skip to content

Commit

Permalink
Update statements.md
Browse files Browse the repository at this point in the history
Added examples for labeled nextcase in switch statements
  • Loading branch information
alexveden authored and lerno committed Jan 17, 2025
1 parent 23700ce commit b91d44c
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions src/content/docs/Language Fundamentals/statements.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,21 +93,29 @@ switch (i)
}
```

It's also possible to use `nextcase` with an expression, to jump to an arbitrary case:
It's also possible to use `nextcase` with an expression, to jump to an arbitrary case or between labeled switch statements:

```c3
switch (i)
{
case 1:
doSomething();
nextcase 3; // Jump to case 3
case 2:
doSomethingElse();
case 3:
nextcase rand(); // Jump to random case
switch MAIN: (enum_var)
case FOO:
switch (i)
{
case 1:
doSomething();
nextcase 3; // Jump to case 3
case 2:
doSomethingElse();
case 3:
nextcase rand(); // Jump to random case
default:
io::printn("Ended");
nextcase MAIN: BAR; // Jump to outer (MAIN) switch
}
case BAR:
io::printn("BAR");
default:
io::printn("Ended");
}
break;
}
```

Which can be used as structured `goto` when creating state machines.
Expand Down

0 comments on commit b91d44c

Please sign in to comment.