Here are 3 Kinds of Looping Algorithms and Examples of Programs
In writing a programming language, sometimes we want to write the same command in many iterations, for example hundreds, thousands and even millions. Of course it will take a long time and energy to write down the commands one by one.
Therefore, in the Pascal language there is a function called looping. Looping (or loop) itself is defined as a programming language that functions to run lines of code repeatedly as long as the conditions are still met.
3 Kinds of Looping Algorithms and Examples of Programs
It turns out that there are 3 kinds of Looping in Looping Algorithms. Fortunately, these three algorithms will be discussed in detail by Dafunda Tekno
1. For Loop Algorithm
The for loop algorithm is divided into two, namely For. . . to . . . do for positive loops and For . . . down. . . to for negative loops. Or more clearly, you can see the following two divisions of the iteration algorithm.
A. Loop Algorithm For…to..do
Algorithm For . . to. . .do loops sequentially from the smallest number to the largest number. This algorithm has a structure like this
For variabel:=kondisiAwal to kondisiAkhir do statemen;
Pascal’s example program for looping algorithms. . . to . . . do
Program Loop1;uses crt;var i:integer;Begin For i:=1 to 100 do Begin writeln('Nama Saya'); End; Readln;end.
B. Loop Algorithm For…downto..do
Algorithm For . . to. . .do loops sequentially from the largest number to the smallest number. This algorithm has a structure like this
For variabel:=kondisiAwal downto kondisiAkhir do statemen
Example of a For..downto…do . Loop Algorithm program
Program Loop2;uses crt;var i:integer;Begin For i:=100 downto 1 do Begin writeln('Nama Saya'); End; Readln;end.
2. While Do Loop Algorithm
The While Do Loop Algorithm is an algorithm that repeats the “statement” as long as the condition is still met. As long as the statement is worth wrongthe statement will continue to be repeated.
The structure of the while do loop algorithm is
While kondisi Do Statemen;
Example of while do algorithm program
Program Loop3;uses crt;var i:integer;Begin i:=0; while i<4 do begin writeln(i); i:=i+1; end; Readln;end.
3. Repeat-Until Loop Algorithm
The repeat-until algorithm is an algorithm that repeats the “statement” so that the (Until) condition is met. As long as the statement is worth wrongthe statement will be repeated until the value is true.
The Repeat-Until Algorithm statement is processed at least 1 time. Below is the structure of the Repeat-Until Algorithm
Repeat Statemen1; Statemen2; ... Statemen;Until kondisi;
Example of a Pascal Repeat-Until program
program repeat_until;uses crt;var i: integer;begin clrscr; i:= 0; repeat begin writeln('Hello World'); i:= i + 1; end; until i = 10; readln;end.
The program will produce output like this:

Now that is an explanation of the various iteration algorithms. How easy is it? If anyone is confused, we can discuss it in the comments column.