What Will I Learn?
STATEMENT OF CONTROL – LOOPING
- FOR
- WHILE
- DO...WHILE
Requirements
Dev C++ 5
Difficulty
Intermediate
Tutorial Contents
BASIC THEORY
Looping is a repetition of the commandments until it reaches a specific State. Looping structure consists of two parts:
- Boolean expression i.e. repetition of the Conditions that must be met to implement looping
- Content or looping that is one or more statements (action) that will be repeated.
It is basically a process of looping is closely related to the control of the test. Where is the control test is used to stop any recurring activities if it meets a certain requirement.
A.FORM OF LOOPING FOR
Statement for use to produce a repeat (looping) several times without the use of any condition. It is generally performed by looping for already known limits early, looping and changes. As long as the conditions are met, then the statement will continue to be executed.
The form of the structure of looping for are as follows:
for (initialization; condition; changes)
{
The statement;
}
The explanation of parts for:
- The
initializationsection mandatory limits are given as the beginning of an iteration. - Part of the optional
conditions, i.e. If is given then the process will last for a looping condition meets the conditions. But if not, then the process of looping will be performed without limit. - Part of the
changeis also optional, i.e. If is given then the looping process will take place along with the process of change of the independent variable. The reverse process of looping will take place with the contents of the variable variables constant/fixed.
Exercise
int main ()
{
printf("\n \n utopian-io");
int i;
for(i=1;i<=10;i++)
{
printf ("\n \n the usage FOR practical work By Cuthamza ");
printf (" %d\t \n\n", i);
}
return 0;
}
work result
B.FORM OF LOOPING WHILE
Statement of the while statement is one which is useful to process a statement or multiple statements several times without being noticed certainly many times that the looping will be performed. Statement while allowing the existing statement-statement therein is not do at all. The general structure of looping while is as follows:
Initialization;
While (condition)
{
statement;
Change;
}
statement will be executed (run) when the condition is true (condition fulfilled), if the condition is already worth wrong then the iteration will stop.
Exercise
int main()
{
printf("\n \n utopian-io");
int i;
i=1;
while(i<=10)
{
printf("\n \n Practical Usage WHILE By Cuthamza ");
printf("%d\t",i);
i=i+1;
}
return 0;
}
work result
C.FORM OF LOOPING THE DO ... WHILE
Statement of the do ... while statement like while, just on the do ... while, statements contained therein at least once will be executed. The General form of looping the do ... while is:
Initialization;
do {
statement;
change;
} while (condition);
statement will be executed as long as the condition is still in a State of true. The same as looping while, just that statement will be executed at least once.
Exercise
int main()
{
printf("\n \n utopian-io");
int i;
i=1;
do
{
printf("\n \n Practical use of DO-WHILE By Cuthamza ");
printf("%d\t",i);
i=i+1;
}while(i<=10);
return 0;
}
work result
Finish
Thank you visit my article.
Posted on Utopian.io - Rewarding Open Source Contributors