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
For loop
(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!
===Vectorised for-loops=== Some languages offer a for-loop that acts as if processing all iterations [[Automatic vectorization|in parallel]], such as the {{code|for all}} keyword in [[Fortran 95]] which has the interpretation that ''all'' [[Sides of an equation|right-hand-side]] expressions are evaluated before ''any'' assignments are made, as distinct from the explicit iteration form. For example, in the {{code|for}} statement in the following pseudocode fragment, when calculating the new value for {{code|A(i)}}, except for the first (with {{code|1=i = 2}}) the reference to {{code|A(i - 1)}} will obtain the new value that had been placed there in the previous step. In the {{code|for all}} version, however, each calculation refers only to the original, unaltered {{code|A}}. '''for''' i := 2 : N - 1 '''do''' A(i) := [A(i - 1) + A(i) + A(i + 1)] / 3; '''next''' i; '''for all''' i := 2 : N - 1 '''do''' A(i) := [A(i - 1) + A(i) + A(i + 1)] / 3; The difference may be significant. Some languages (such as PL/I, Fortran 95) also offer array assignment statements, that enable many for-loops to be omitted. Thus pseudocode such as {{code|1=A:= 0;}} would set all elements of array A to zero, no matter its size or dimensionality. The example loop could be rendered as <syntaxhighlight lang="Fortran"> A(2 : N - 1) := [A(1 : N - 2) + A(2 : N - 1) + A(3 : N)] / 3; </syntaxhighlight> But whether that would be rendered in the style of the for-loop or the for-all-loop or something else may not be clearly described in the compiler manual.
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)