Go for: Difference between revisions
Jump to navigation
Jump to search
Line 29: | Line 29: | ||
=<tt>for</tt> Controlled by a "for" Clause= | =<tt>for</tt> Controlled by a "for" Clause= | ||
<pre> | |||
for i := 0; i < 10; i++ { | |||
// do something | |||
} | |||
</pre> | |||
=<tt>for</tt> Controlled by a "range" Clause= | =<tt>for</tt> Controlled by a "range" Clause= |
Revision as of 05:21, 23 March 2016
External
- Language Specification for Statements https://golang.org/ref/spec#For_statements
Internal
Overview
A for statement specifies repeated execution of a block. For more details on blocks, see Go blocks.
The iteration is controlled by a condition, a "for" clause, or a "range" clause.
for Controlled by a Condition
for a < b { a *= 2 }
The condition is evaluated before each iteration. If the condition is absent, is equivalent with true.
for { // do this forever }
for Controlled by a "for" Clause
for i := 0; i < 10; i++ { // do something }