Go for: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 17: Line 17:
for a < b {
for a < b {
     a *= 2
     a *= 2
}
</pre>
The condition is evaluated before each iteration. If the condition is absent, is equivalent with <tt>true</tt>.
<pre>
for {
    // do this forever
}
}
</pre>
</pre>

Revision as of 05:19, 23 March 2016

External

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 Controlled by a "range" Clause