Rabu, 05 November 2008

Repetation

In all programming language repetation include to write the program if the program need it. Repetation repeat the operation in the body or block of this repetation. Repetation usually called like looping.
If we know the number of looping or the end of the loop we can use for() loop, than if we dont know how the loop will be ended we use while() loop. If the execution is minimal one we use do while().

Looping using for

for (j=1, i = 5 ; i > 0 ; i--)
j = j*i;

This for loop means variable of j times with i and it's include into j variable. The output of this program is j is equal to 120.


Looping using while

while (condition is true)
{
execute the statement in this block
}
//
{ } it's a block.


Looping using dowhile
do
{
execut the statement in this block
} while (condition is true);
// ; dont forget to add semmicolon if we use c language.

These three are the basic of the repetition.


by: Chrifto M Sepang

for more information contact me at:
chrifto@gmail.com, or
chrifto@yahoo.co.id

Tidak ada komentar: