moved info from .sh to .go
This commit is contained in:
parent
00c4faf11e
commit
c6164f252f
@ -29,6 +29,7 @@ func main() {
|
|||||||
// The `:=` syntax is shorthand for declaring and
|
// The `:=` syntax is shorthand for declaring and
|
||||||
// initializing a variable, e.g. for
|
// initializing a variable, e.g. for
|
||||||
// `var f string = "apple"` in this case.
|
// `var f string = "apple"` in this case.
|
||||||
|
// This syntax is only available inside functions.
|
||||||
f := "apple"
|
f := "apple"
|
||||||
fmt.Println(f)
|
fmt.Println(f)
|
||||||
}
|
}
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
736ce4018f275bb8d12e5232349bae93611506b2
|
9aeef52b289d7ad9b9ac79f129d4e49f956c60ef
|
||||||
iYyAIilyBRf
|
N5rWndIliJW
|
||||||
|
@ -4,9 +4,3 @@ initial
|
|||||||
true
|
true
|
||||||
0
|
0
|
||||||
apple
|
apple
|
||||||
|
|
||||||
# The shorthand `:=` initialization of variable can
|
|
||||||
# only be used inside any function.
|
|
||||||
# If used outside any function, it would generate
|
|
||||||
# `syntax error: non-declaration statement outside
|
|
||||||
# function body`.
|
|
||||||
|
24
public/variables
generated
24
public/variables
generated
@ -43,7 +43,7 @@ calls.</p>
|
|||||||
|
|
||||||
</td>
|
</td>
|
||||||
<td class="code leading">
|
<td class="code leading">
|
||||||
<a href="https://go.dev/play/p/iYyAIilyBRf"><img title="Run code" src="play.png" class="run" /></a><img title="Copy code" src="clipboard.png" class="copy" />
|
<a href="https://go.dev/play/p/N5rWndIliJW"><img title="Run code" src="play.png" class="run" /></a><img title="Copy code" src="clipboard.png" class="copy" />
|
||||||
<pre class="chroma"><span class="kn">package</span> <span class="nx">main</span>
|
<pre class="chroma"><span class="kn">package</span> <span class="nx">main</span>
|
||||||
</pre>
|
</pre>
|
||||||
</td>
|
</td>
|
||||||
@ -133,7 +133,8 @@ zero value for an <code>int</code> is <code>0</code>.</p>
|
|||||||
<td class="docs">
|
<td class="docs">
|
||||||
<p>The <code>:=</code> syntax is shorthand for declaring and
|
<p>The <code>:=</code> syntax is shorthand for declaring and
|
||||||
initializing a variable, e.g. for
|
initializing a variable, e.g. for
|
||||||
<code>var f string = "apple"</code> in this case.</p>
|
<code>var f string = "apple"</code> in this case.
|
||||||
|
This syntax is only available inside functions.</p>
|
||||||
|
|
||||||
</td>
|
</td>
|
||||||
<td class="code">
|
<td class="code">
|
||||||
@ -154,7 +155,7 @@ initializing a variable, e.g. for
|
|||||||
<td class="docs">
|
<td class="docs">
|
||||||
|
|
||||||
</td>
|
</td>
|
||||||
<td class="code leading">
|
<td class="code">
|
||||||
|
|
||||||
<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,21 +166,6 @@ 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>
|
||||||
|
|
||||||
|
|
||||||
@ -195,7 +181,7 @@ function body</code>.</p>
|
|||||||
</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('');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('');
|
||||||
</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