docs: addition to variables page
This commit is contained in:
parent
4f981a6e0f
commit
00c4faf11e
19
public/variables
generated
19
public/variables
generated
@ -154,7 +154,7 @@ initializing a variable, e.g. for
|
|||||||
<td class="docs">
|
<td class="docs">
|
||||||
|
|
||||||
</td>
|
</td>
|
||||||
<td class="code">
|
<td class="code leading">
|
||||||
|
|
||||||
<pre class="chroma"><span class="gp">$</span> go run variables.go
|
<pre class="chroma"><span class="gp">$</span> go run variables.go
|
||||||
<span class="go">initial
|
<span class="go">initial
|
||||||
@ -165,6 +165,21 @@ initializing a variable, e.g. for
|
|||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td class="docs">
|
||||||
|
<p>The shorthand <code>:=</code> initialization of variable can
|
||||||
|
only be used inside any function.
|
||||||
|
If used outside any function, it would generate
|
||||||
|
<code>syntax error: non-declaration statement outside
|
||||||
|
function body</code>.</p>
|
||||||
|
|
||||||
|
</td>
|
||||||
|
<td class="code empty">
|
||||||
|
|
||||||
|
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
|
||||||
@ -180,7 +195,7 @@ initializing a variable, e.g. for
|
|||||||
</div>
|
</div>
|
||||||
<script>
|
<script>
|
||||||
var codeLines = [];
|
var codeLines = [];
|
||||||
codeLines.push('');codeLines.push('package main\u000A');codeLines.push('import \"fmt\"\u000A');codeLines.push('func main() {\u000A');codeLines.push(' var a \u003D \"initial\"\u000A fmt.Println(a)\u000A');codeLines.push(' var b, c int \u003D 1, 2\u000A fmt.Println(b, c)\u000A');codeLines.push(' var d \u003D true\u000A fmt.Println(d)\u000A');codeLines.push(' var e int\u000A fmt.Println(e)\u000A');codeLines.push(' f :\u003D \"apple\"\u000A fmt.Println(f)\u000A}\u000A');codeLines.push('');
|
codeLines.push('');codeLines.push('package main\u000A');codeLines.push('import \"fmt\"\u000A');codeLines.push('func main() {\u000A');codeLines.push(' var a \u003D \"initial\"\u000A fmt.Println(a)\u000A');codeLines.push(' var b, c int \u003D 1, 2\u000A fmt.Println(b, c)\u000A');codeLines.push(' var d \u003D true\u000A fmt.Println(d)\u000A');codeLines.push(' var e int\u000A fmt.Println(e)\u000A');codeLines.push(' f :\u003D \"apple\"\u000A fmt.Println(f)\u000A}\u000A');codeLines.push('');codeLines.push('');
|
||||||
</script>
|
</script>
|
||||||
<script src="site.js" async></script>
|
<script src="site.js" async></script>
|
||||||
</body>
|
</body>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user