mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
doc: move goto section under statements (#16179)
This commit is contained in:
50
doc/docs.md
50
doc/docs.md
@@ -64,6 +64,7 @@ To do so, run the command `v up`.
|
|||||||
* [For loop](#for-loop)
|
* [For loop](#for-loop)
|
||||||
* [Match](#match)
|
* [Match](#match)
|
||||||
* [Defer](#defer)
|
* [Defer](#defer)
|
||||||
|
* [Goto](#goto)
|
||||||
* [Structs](#structs)
|
* [Structs](#structs)
|
||||||
* [Heap structs](#heap-structs)
|
* [Heap structs](#heap-structs)
|
||||||
* [Default field values](#default-field-values)
|
* [Default field values](#default-field-values)
|
||||||
@@ -159,7 +160,6 @@ To do so, run the command `v up`.
|
|||||||
* [Cross-platform shell scripts in V](#cross-platform-shell-scripts-in-v)
|
* [Cross-platform shell scripts in V](#cross-platform-shell-scripts-in-v)
|
||||||
* [Vsh scripts with no extension](#vsh-scripts-with-no-extension)
|
* [Vsh scripts with no extension](#vsh-scripts-with-no-extension)
|
||||||
* [Attributes](#attributes)
|
* [Attributes](#attributes)
|
||||||
* [Goto](#goto)
|
|
||||||
* [Appendices](#appendices)
|
* [Appendices](#appendices)
|
||||||
* [Keywords](#appendix-i-keywords)
|
* [Keywords](#appendix-i-keywords)
|
||||||
* [Operators](#appendix-ii-operators)
|
* [Operators](#appendix-ii-operators)
|
||||||
@@ -1954,6 +1954,30 @@ fn main() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Goto
|
||||||
|
|
||||||
|
V allows unconditionally jumping to a label with `goto`. The label name must be contained
|
||||||
|
within the same function as the `goto` statement. A program may `goto` a label outside
|
||||||
|
or deeper than the current scope. `goto` allows jumping past variable initialization or
|
||||||
|
jumping back to code that accesses memory that has already been freed, so it requires
|
||||||
|
`unsafe`.
|
||||||
|
|
||||||
|
```v ignore
|
||||||
|
if x {
|
||||||
|
// ...
|
||||||
|
if y {
|
||||||
|
unsafe {
|
||||||
|
goto my_label
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
my_label:
|
||||||
|
```
|
||||||
|
`goto` should be avoided, particularly when `for` can be used instead.
|
||||||
|
[Labelled break/continue](#labelled-break--continue) can be used to break out of
|
||||||
|
a nested loop, and those do not risk violating memory-safety.
|
||||||
|
|
||||||
## Structs
|
## Structs
|
||||||
|
|
||||||
```v
|
```v
|
||||||
@@ -6249,30 +6273,6 @@ fn main() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Goto
|
|
||||||
|
|
||||||
V allows unconditionally jumping to a label with `goto`. The label name must be contained
|
|
||||||
within the same function as the `goto` statement. A program may `goto` a label outside
|
|
||||||
or deeper than the current scope. `goto` allows jumping past variable initialization or
|
|
||||||
jumping back to code that accesses memory that has already been freed, so it requires
|
|
||||||
`unsafe`.
|
|
||||||
|
|
||||||
```v ignore
|
|
||||||
if x {
|
|
||||||
// ...
|
|
||||||
if y {
|
|
||||||
unsafe {
|
|
||||||
goto my_label
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// ...
|
|
||||||
}
|
|
||||||
my_label:
|
|
||||||
```
|
|
||||||
`goto` should be avoided, particularly when `for` can be used instead.
|
|
||||||
[Labelled break/continue](#labelled-break--continue) can be used to break out of
|
|
||||||
a nested loop, and those do not risk violating memory-safety.
|
|
||||||
|
|
||||||
# Appendices
|
# Appendices
|
||||||
|
|
||||||
## Appendix I: Keywords
|
## Appendix I: Keywords
|
||||||
|
Reference in New Issue
Block a user