Skip to main content
Informatik.uz
Chapter 1. Types of Algorithms

Repeating Algorithms and Loops

A loop makes it easy to repeat actions many times. We study the loop body, kinds of loops and endless loops, and add up the numbers from 1 to 5.

Topic 2 of 111 min readUpdated October 27, 2026
All topics (2 of 11)

Sometimes the same actions have to be repeated many times, for example climbing 10 steps of a staircase. Instead of writing every step separately, it is easier to say “repeat 10 times: climb one step”. An algorithm in which commands are carried out again and again is called a repeating (looping) algorithm.

The group of commands that is repeated is called the loop body. There are two kinds of loops: those with a known number of repetitions and those that continue until a condition is met. In the second kind the condition is checked each time, for example “pour water until the glass is full”.

Example: let us add up the numbers from 1 to 5. We start with the sum s = 0 and the counter i = 1. The loop body performs s = s + i and i = i + 1; when the counter becomes greater than 5, the loop stops and the result is 15.

It is very important to write the stopping condition correctly. If the condition is never met, the loop goes on forever and the program “freezes”. That is why the loop body must contain a change that affects the condition, such as increasing the counter.

Key takeaways

  • In a looping algorithm, a group of commands is carried out several times.
  • The repeated commands are called the loop body.
  • The number of repetitions may be known in advance or depend on a condition.
  • If the stopping condition is wrong, the loop never ends.

Practice tasks

  1. Write out the task “Write your name in your notebook 5 times” in words, first without a loop and then with a loop, and compare the two versions.
  2. Draw a flowchart for finding the sum of the numbers from 1 to 5 and record in a table how the values of s and i change.
  3. Find two examples of a looping algorithm in everyday life (for example, climbing stairs or filling a container) and state when each of them stops.

Review questions

Test yourself: think first, then reveal the answer.

  1. 1What is the loop body?
    The group of commands that are repeated inside the loop.
  2. 2When does an endless loop occur?
    When the stopping condition is never met, for example if the counter is not changed inside the loop.
  3. 3What is the sum of the numbers from 1 to 5?
    The sum is 15: 1 + 2 + 3 + 4 + 5 = 15.

0 of 11 topics completed

Sign in to mark
Informatika 7-sinf darsligi muqovasi
In the textbookInformatics — Grade 7