Loop

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
  • 1661

    Greg Bernhardt

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

    moenste

    A PF Atom 31 From Moscow
    • Messages
      711
    • Reaction score
      12
    • Points
      32
  • 2

    acurate

    A PF Quark
    • Messages
      17
    • Reaction score
      1
    • Points
      1
  • 1

    Yashbhatt

    A PF Molecule From India
    • Messages
      348
    • Reaction score
      13
    • Points
      73
  • 1

    Swamp Thing

    A PF Mountain
    • Messages
      908
    • Media
      93
    • Reaction score
      572
    • Points
      268
  • 1

    Jairo Rodriguez

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

    OskarBillington

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

    Guineafowl

    A PF Molecule
    • Messages
      762
    • Reaction score
      366
    • Points
      98
  • 1

    Indira_Clueless

    A PF Electron
    • Messages
      12
    • Reaction score
      0
    • Points
      11
  • 1

    dykuma

    A PF Molecule 29
    • Messages
      56
    • Reaction score
      7
    • Points
      66
  • 1

    kodama

    A PF Cell
    • Messages
      978
    • Reaction score
      132
    • Points
      108
  • 1

    komarxian

    A PF Electron From Nunya.
    • Messages
      37
    • Reaction score
      0
    • Points
      19
  • 1

    Erik P

    A PF Quark From Denmark
    • Messages
      33
    • Reaction score
      0
    • Points
      1
  • 1

    mick5000x

    A PF Electron
    • Messages
      5
    • Reaction score
      0
    • Points
      11
  • 1

    Afterthought

    A PF Electron
    • Messages
      29
    • Reaction score
      2
    • Points
      16
  • 1

    EpicFishFingers

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

    Gabriel Maia

    A PF Atom
    • Messages
      72
    • Reaction score
      1
    • Points
      31
  • 1

    Hijaz Aslam

    A PF Electron
    • Messages
      66
    • Reaction score
      1
    • Points
      11
  • 1

    tim9000

    A PF Cell
    • Messages
      867
    • Reaction score
      17
    • Points
      103
  • 1

    Alexander Max

    A PF Quark
    • Messages
      3
    • Reaction score
      0
    • Points
      1
  • Back
    Top