spec: add subtitles to section on "for" statements

This matches what we already do for switch statements and makes
this large section more visibly organized. No other changes besides
introducing the titles.

Fixes #4486.

Change-Id: I73f274e4fdd27c6cfeaed79090b4553e57a9c479
Reviewed-on: https://go-review.googlesource.com/33410
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
Robert Griesemer 2016-11-18 10:49:29 -08:00
parent d0b3c169ac
commit b01f612a69

View File

@ -4799,8 +4799,8 @@ The "fallthrough" statement is not permitted in a type switch.
<h3 id="For_statements">For statements</h3>
<p>
A "for" statement specifies repeated execution of a block. The iteration is
controlled by a condition, a "for" clause, or a "range" clause.
A "for" statement specifies repeated execution of a block. There are three forms:
The iteration may be controlled by a single condition, a "for" clause, or a "range" clause.
</p>
<pre class="ebnf">
@ -4808,6 +4808,8 @@ ForStmt = "for" [ Condition | ForClause | RangeClause ] Block .
Condition = Expression .
</pre>
<h4 id="For_condition">For statements with single condition</h4>
<p>
In its simplest form, a "for" statement specifies the repeated execution of
a block as long as a boolean condition evaluates to true.
@ -4822,6 +4824,8 @@ for a &lt; b {
}
</pre>
<h4 id="For_clause">For statements with <code>for</code> clause</h4>
<p>
A "for" statement with a ForClause is also controlled by its condition, but
additionally it may specify an <i>init</i>
@ -4860,6 +4864,8 @@ for cond { S() } is the same as for ; cond ; { S() }
for { S() } is the same as for true { S() }
</pre>
<h4 id="For_range">For statements with <code>range</code> clause</h4>
<p>
A "for" statement with a "range" clause
iterates through all entries of an array, slice, string or map,