Wednesday, October 10, 2018

Program Control : Repetition

Ever heard of loops? Repetition in programming is it! Basically we are creating loops in programming and it is called "repetition"

Here are some types of repetitions in programming world:

1. For

Syntax :

for( initial value ; condition ; statement){
       statement;
       statement;      //this is a counted loop because we'll certainly know how many loops there are
       ................
}

2. While

Syntax:

while( condition ){
        statement;
        statement;
        ................    //this is a leading decision loop because the condition is located on the lead(top)                                       and the end of the loop isn't certain because it is not counted.
}

3. Do-while

Syntax:

do{
    statement;
    statement;   //this is a trailing decision loop, it needs a statement/action first before putting it into                              judgement whether the loops goes again or breaks.
    ................
}while( condition );

There are some statements that are used for doing some necessary things in loops, there are:

1. Continue

It is used to skip a loop, basically just saying that nothing happens in some certain of conditions.

2. Break

It is used to break a loop, so the loop ends if it fulfills the condition needed.

No comments:

Post a Comment