Skip to content

Commit cf16443

Browse files
committed
fix a couple of typos.
add a mention of range to the tutorial. change tutorial's title. R=rsc CC=golang-dev https://golang.org/cl/152098
1 parent 6634e34 commit cf16443

File tree

3 files changed

+37
-5
lines changed

3 files changed

+37
-5
lines changed

doc/go_spec.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -3010,7 +3010,7 @@ <h3 id="Method_expressions">Method expressions</h3>
30103010
</p>
30113011

30123012
<pre>
3013-
func (tv *T, f int) int
3013+
func (tv *T, a int) int
30143014
</pre>
30153015

30163016
<p>

doc/go_tutorial.html

+20-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- Let's Go -->
1+
<!-- A Tutorial for the Go Programming Language -->
22
<h2>Introduction</h2>
33
<p>
44
This document is a tutorial introduction to the basics of the Go programming
@@ -340,6 +340,24 @@ <h2>An Interlude about Types</h2>
340340
makes its first appearance in <code>sum</code>. It works on strings, arrays,
341341
slices, maps, and channels.
342342
<p>
343+
By the way, another thing that works on strings, arrays, slices, maps
344+
and channels is the <code>range</code> clause on <code>for</code> loops. Instead of writing
345+
<p>
346+
<pre>
347+
for i := 0; i < len(a); i++ { ... }
348+
</pre>
349+
<p>
350+
to loop over the elements of a slice (or map or ...) , we could write
351+
<p>
352+
<pre>
353+
for i, v := range a { ... }
354+
</pre>
355+
<p>
356+
This assigns <code>i</code> to the index and <code>v</code> to the value of the successive
357+
elements of the target of the range. See
358+
<a href='/doc/effective_go.html'>Effective Go</a>
359+
for more examples of its use.
360+
<p>
343361
<p>
344362
<h2>An Interlude about Allocation</h2>
345363
<p>
@@ -511,7 +529,7 @@ <h2>An I/O Package</h2>
511529
</pre>
512530
<p>
513531
There are a number of new things in these few lines. First, <code>Open</code> returns
514-
multiple values, an <code>File</code> and an error (more about errors in a moment).
532+
multiple values, a <code>File</code> and an error (more about errors in a moment).
515533
We declare the
516534
multi-value return as a parenthesized list of declarations; syntactically
517535
they look just like a second parameter list. The function

doc/go_tutorial.txt

+16-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- Let's Go -->
1+
<!-- A Tutorial for the Go Programming Language -->
22
Introduction
33
----
44

@@ -264,6 +264,20 @@ The built-in function "len()", which returns number of elements,
264264
makes its first appearance in "sum". It works on strings, arrays,
265265
slices, maps, and channels.
266266

267+
By the way, another thing that works on strings, arrays, slices, maps
268+
and channels is the "range" clause on "for" loops. Instead of writing
269+
270+
for i := 0; i < len(a); i++ { ... }
271+
272+
to loop over the elements of a slice (or map or ...) , we could write
273+
274+
for i, v := range a { ... }
275+
276+
This assigns "i" to the index and "v" to the value of the successive
277+
elements of the target of the range. See
278+
<a href='/doc/effective_go.html'>Effective Go</a>
279+
for more examples of its use.
280+
267281

268282
An Interlude about Allocation
269283
----
@@ -391,7 +405,7 @@ exported factory to use is "Open":
391405
--PROG progs/file.go /func.Open/ /^}/
392406

393407
There are a number of new things in these few lines. First, "Open" returns
394-
multiple values, an "File" and an error (more about errors in a moment).
408+
multiple values, a "File" and an error (more about errors in a moment).
395409
We declare the
396410
multi-value return as a parenthesized list of declarations; syntactically
397411
they look just like a second parameter list. The function

0 commit comments

Comments
 (0)