Thursday, October 11, 2018

Program Control Repetition


So here is the important things from Algorithm and Programming class.

REPETITION

Repetition is one or more instruction that is/are repeated for a certain amount of time.
There are 4 types of repetition operation. There are :
1. for
2. while
3. do-while
4. goto (This operation is not used much during programming)

The syntax for For is :

for(exp1; exp2; exp3)
{
     statement;
}
exp1 : initialization
exp2 : condition
exp3 : increment (++) or decrement (--)

The syntax for While is :
while ( exp )
{
     statement; 
}

The syntax for Do-While is :
do
{
     statement;
}
while ( exp )

The difference between while and do-while is :
while operation checks the condition first then run the statement while
the do-while operation run the statement first then check the condition later.