</>Learn to Write Code
LearnPseudocodeReal CodeLanguagesVideosCode TalkAbout
Learn → Programming Fundamentals → Loops & Repetition

Programming Fundamentals

01Variables02Operators03Input & Output04Sequence05Conditions06Loops07Functions08Objects
Lesson 6 of 8·Beginner

Loops & Repetition

Repeat instructions without copying the same code over and over.

Related:looprepeatwhileforiteration

A loop repeats work

A loop tells the computer to repeat some instructions.

Instead of writing SHOW 1, SHOW 2, SHOW 3, and so on, we can store a counter, repeat while it is within our limit, and add one each time.

Every repeating loop needs a way to stop. Otherwise it can repeat forever.
Try it: If a counter starts at 1 and you add one after every repetition, what condition would make it stop after displaying 10?

Repeat while the condition is true

The counter changes each time, eventually making the loop condition false.

Pseudocode
CREATE count AS 1

REPEAT WHILE count LESS OR EQUAL TO 5
    SHOW count
    ADD ONE TO count
END REPEAT

The same idea in Python

Python uses while for the same repeating condition.

Python
count = 1

while count <= 5:
    print(count)
    count += 1

The same idea in JavaScript

JavaScript uses while and ++ to add one to the counter.

JavaScript
let count = 1;

while (count <= 5) {
    console.log(count);
    count++;
}

The same idea in C#

C# uses the same while structure for this loop.

C#
int count = 1;

while (count <= 5)
{
    Console.WriteLine(count);
    count++;
}

The same idea in Java

Java expresses this loop almost exactly like C# and JavaScript.

Java
int count = 1;

while (count <= 5) {
    System.out.println(count);
    count++;
}

The same idea in C++

C++ uses the same counter and stopping condition.

C++
int count = 1;

while (count <= 5)
{
    std::cout << count << '\n';
    count++;
}
Lesson 6 of 8 · Concept
← Previous Lesson: ConditionsNext Lesson: Functions →

Learn to Write Code

Learn the idea first, write it in pseudocode, then see how real programming languages express the same logic.

Learn

CurriculumPseudocode StandardLanguagesReal Code

Elsewhere

Code TalkAbout BriancodeBetter on YouTubeSupporting files on GitHubAdvertising & Promotions
© 2026 Learn to Write Code. Educational content and examples are provided for learning purposes.