General and Web Programming Fundamentals
  • Introduction
  • Program creation and design
    • Program design
      • Algorithms
      • Pseudocode
    • Programming conventions
    • Writing programs
      • Source code editors
      • Integrated Development Environments
      • Code repositories/Version control
      • Compilers/Interpreters
  • Programming Fundamentals
    • Operators
      • Arithmetic
      • Logical
      • Assignment
    • Constants and Variables
    • Datatypes
      • Primitive Datatypes
        • Character
        • Integer
        • Boolean
        • Floating point
        • Nothing (Null)
      • Composite Datatypes
        • Arrays
        • Strings
        • Classes
        • Structs
      • Literals
    • Data structures
      • Lists
      • Queues
      • Stacks
      • Map/dictionary
      • Trees
      • Graphs
    • Control structures
      • Selection (Conditional)
        • If/Else
        • Ternary
        • Switch
      • Iteration (Loops)
        • For loops
        • While loops
        • Do-While loops
        • For-Each loops
    • Functions
      • Parameters and arguments
      • Lambda expressions
      • Higher Order Functions
    • Space and Time
    • Scope
    • Standard libraries
  • Programming Paradigms
    • Procedural (Imperative) Programming
    • Object-oriented programming
    • Functional Programming
    • Declarative Programming
    • Event Driven programming
  • Programming Languages
    • Short history of programming
    • Low-level programming languages
    • High-level programming languages
  • Web Development
    • What is the web?
      • Web browsers (clients)
      • Webservers (serving web pages)
      • W3C
    • Markup languages
      • HTML
        • HTML Tags
      • Cascading Style Sheets (CSS)
        • CSS Properties
      • XML
      • Markdown
    • Scripting Languages
      • JavaScript
      • TypeScript
    • JSON
    • JavaScript Frameworks
  • Acknowledgements
    • About the author(s)
  • License
Powered by GitBook
On this page

Was this helpful?

Export as PDF
  1. Programming Fundamentals
  2. Control structures

Iteration (Loops)

Iteration (Loops) in Computer Programming

Iteration, commonly known as looping, is a fundamental concept in computer programming that allows a block of code to be executed repeatedly, based on a specified condition. This process enables programmers to efficiently manage repetitive tasks by reducing the amount of code they need to write and maintain.

Types of Iteration

There are several types of loops, but the most commonly used ones include:

  • For Loop: Executes a block of code a predetermined number of times.

  • While Loop: Repeats a block of code as long as a specified condition is true.

  • Do-While Loop: Similar to the while loop, but it executes the block of code once before checking the condition.

  • For-Each Loop: The for-each loop, also known as the enhanced for loop, is a special type of loop that simplifies the iteration over collections, such as arrays. It eliminates the need for using a counter or index variable to access the elements of the array or collection.

Using Loops with Arrays

Loops are often used in conjunction with arrays to perform operations on each element of the array. For example, a for loop can be used to iterate over the elements of an array, performing calculations, displaying them, or modifying them as needed.

PreviousSwitchNextFor loops

Last updated 1 year ago

Was this helpful?