Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
C syntax
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Iteration statements=== C has three forms of [[iteration]] statement: <syntaxhighlight lang=C> do <statement> while ( <expression> ) ; while ( <expression> ) <statement> for ( <expression> ; <expression> ; <expression> ) <statement> </syntaxhighlight> In the [[while loop|{{code|while}}]] and {{code|do}} statements, the sub-statement is executed repeatedly so long as the value of the {{code|expression}} remains non-zero (equivalent to true). With {{code|while}}, the test, including all side effects from {{code|<expression>}}, occurs before each iteration (execution of {{code|<statement>}}); with {{code|do}}, the test occurs after each iteration. Thus, a {{code|do}} statement always executes its sub-statement at least once, whereas {{code|while}} may not execute the sub-statement at all. The statement: <syntaxhighlight lang=C> for (e1; e2; e3) s; </syntaxhighlight> is equivalent to: <syntaxhighlight lang=C> e1; while (e2) { s; cont: e3; } </syntaxhighlight> except for the behaviour of a {{code|continue;}} statement (which in the {{code|for}} loop jumps to {{code|e3}} instead of {{code|e2}}). If {{code|e2}} is blank, it would have to be replaced with a {{code|1}}. Any of the three expressions in the {{code|for}} loop may be omitted. A missing second expression makes the {{code|while}} test always non-zero, creating a potentially infinite loop. Since [[C99]], the first expression may take the form of a declaration, typically including an initializer, such as: <syntaxhighlight lang=C> for (int i = 0; i < limit; ++i) { // ... } </syntaxhighlight> The declaration's scope is limited to the extent of the {{code|for}} loop.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)