Minggu, 30 Oktober 2011

Iteration in C Language

After studying for the input and output in C language selection in the C language, then the next is loop. Loop on the C language is often referred to as "looping" is a process performed repeatedly until a specified threshold or condition recurrence. Usually when the iteration limit is not included then the syntax would be an error because the process will not stop or overloop-ing.
This type of loop in C Language:
a. FOR
      Syntax: for (initialization; repetition requirements; inkrement or decrement)
                     {
                           ...... action .....
                     }

      initialization: setting the initial state of the control variables
      conditions: boolean expression that determines the end of the iteration
      additions: regulatory changes in the value of the variable control

Example:
for (i = 0; i <5; i + +)
{
printf ("I learn programming with C language algorithms in visualAlpro \ n");
 }

b. WHILE
      Syntax: while (condition) {
                     action}
Example:
i = 0
while (i <5)
{
printf ("I learn programming with C language algorithms in visualAlpro \ n");
 i + +;
}

c. DO - WHILE
      Syntax: do {
                     action ..}
                     while (condition);
      Example:
            i = 0;
  do
            {
                 printf ("I learn programming with C language algorithms in visualAlpro \ n");
                 i + +;
  } While (i <4);

Output for all of them are:
I learned programming with C language algorithms in visualAlpro
I learned programming with C language algorithms in visualAlpro
I learned programming with C language algorithms in visualAlpro
I learned programming with C language algorithms in visualAlpro
I learned programming with C language algorithms in visualAlpro


 The difference between the FOR, WHILE, and DO-WHILE:
For: to repeat a perulanga known exactly how many recurrence.
While: Pre Tested Loop
for looping yet unknown number of recurrence. Checking the condition will be done first before doing the action. If the condition still is true, then the loop will continue until the conditions are false.
Do-while: Post Tested Loop
for loops are not yet known amount. Action will be executed first, and then be checked if the condition is true then it is still looping will continue.

Tidak ada komentar:

Posting Komentar