when creating computer programs to solve problems, there are three types of repetition that you can use. Describe the three types of loop and provide a pseudocode example of each
The three types of loops are for loop, while loop, do while loop.
For Loop: This is used when a set of statements are to be executed a specific number of times.This is an entry controlled loop meaning looo terminating condition is checked in the beginning of the loop
Structure of for loop:
for( initialisation ; test condition : update statement )
{
}
Psuedo Code:
for( i = 0 ; i < 5 : i++ )
{
Print " i will be printed 5 times "
}
While Loop: While loop is used when the number of iterations is not known before hand because this is an entry controlled loop.
Structure of loop:
While ( condition )
{
}
Psuedo Code:
i= 1
While ( i < 5)
{
Print " i am a while loop "
}
Do While loop: Do while loop is used when a set of statements need to be executed atleast once before checking the loop terminating condition
Loop Structure:
do
{
} while ( condition ) ;
psuedo Code:
i= 0
do
{
Print " i am a do while loop "
} while ( i < 5 );
Get Answers For Free
Most questions answered within 1 hours.