For loops

In computer science, a for-loop (or simply for loop) is a control flow statement for specifying iteration, which allows code to be executed repeatedly. Various keywords are used to specify this statement: descendants of ALGOL use "for", while descendants of Fortran use "do". There are other possibilities, for example COBOL which uses "PERFORM VARYING".
A for-loop has two parts: a header specifying the iteration, and a body which is executed once per iteration. The header often declares an explicit loop counter or loop variable, which allows the body to know which iteration is being executed. For-loops are typically used when the number of iterations is known before entering the loop. For-loops can be thought of as shorthands for while-loops which increment and test a loop variable.
The name for-loop comes from the word for, which is used as the keyword in many programming languages to introduce a for-loop. The term in English dates to ALGOL 58 and was popularized in the influential later ALGOL 60; it is the direct translation of the earlier German für, used in Superplan (1949–1951) by Heinz Rutishauser, who also was involved in defining ALGOL 58 and ALGOL 60. The loop body is executed "for" the given values of the loop variable, though this is more explicit in the ALGOL version of the statement, in which a list of possible values and/or increments can be specified.
In FORTRAN and PL/I, the keyword DO is used for the same thing and it is called a do-loop; this is different from a do-while loop.

View More On Wikipedia.org
  • 18

    Greg Bernhardt

    A PF Singularity From USA
    • Messages
      19,443
    • Media
      227
    • Reaction score
      10,021
    • Points
      1,237
  • 2

    sukalp

    A PF Quark
    • Messages
      53
    • Reaction score
      2
    • Points
      1
  • 1

    lee403

    A PF Electron
    • Messages
      16
    • Reaction score
      1
    • Points
      24
  • 1

    KonaGorrila

    A PF Atom From Flagstaff, AZ / Kona, HI
    • Messages
      12
    • Reaction score
      0
    • Points
      39
  • 1

    hbz88

    A PF Quark
    • Messages
      2
    • Reaction score
      0
    • Points
      1
  • 1

    WWGD

    A PF Moon
    • Messages
      7,010
    • Reaction score
      10,472
    • Points
      541
  • Back
    Top