This is a creation in Article, where the information may have evolved or changed.
"Go Flow Control"
1. For no (), there must be {}.
2. The for before and after expressions can be empty.
3, no while,for is the while.
4, Infinite cycle.
5. If there is no (), there must be {}.
6, if temporary variable.
Like for
, the if
statement can start with a short statement to execute before the condition.
Variables declared by the statement is only in scope until the end of the if
.
7. If temporary variables can be used in else.
8, switch will automatically break.
9. The expression in case can be calculated.
10, Switch without a condition is the same as switch true
.
11, delay the execution.
A defer statement defers the execution of a function until the surrounding function returns.
The deferred call ' s arguments was evaluated immediately, but the function call was not executed until the surrounding funct Ion returns.
12, Deferred function calls is pushed onto a stack.
Output is 9 8 7 6 ...
Reference: HTTPS://TOUR.GOLANG.ORG/FLOWCONTROL/1