|
Decision Making, Branching & Looping concept in c programming
|
Posted On :
Sep-13-2011
| seen (549) times |
Article Word Count :
473
|
|
Execution of a program is essentially sequential in nature. Statements are executed in the order of their appearance in a program. However, this causes a serious limitation on the programming capabilities.
|
Introduction
Execution of a program is essentially sequential in nature. Statements are executed in the order of their appearance in a program. However, this causes a serious limitation on the programming capabilities. Consequently every programming language provides programming constructs that allow altering the sequence of execution. In this section we will consider, the programming constructs of this type provided with C language.
Control Statement
The statements that allow programmers to alter the sequential flow of execution of the program and control the flow are called control statements. Control statements enable the programmers to specify the order in which the various instructions in a program are to be executed by the computer. In short, they determine the flow of control in a program.
Why Control Statement?
Control statements are probably most desirable feature of any programming language. Consider writing program that prints " HELLO WORLD" 10 times. Without using any control programming construct the program would look like the one listed below:
#include
main( )
{
printf ("HELLO WORLD");
printf ("HELLO WORLD") ;
printf ("HELLO WORLD");
printf ("HELLO WORLD");
printf ("HELLO WORLD");
printf ("HELLO WORLD");
printf ("HELLO WORLD");
printf ("HELLO WORLD");
printf ("HELLO WORLD");
printf ("HELLO WORLD");
Obviously this is not convenient way of programming. Without any control structure you will have to repeat printf statement as many times as you want them to print. Imagine what will you do if you have to print this statement 1000 times. Control statements let you write such programming problems in only few lines. Thus, using for loop (to be discussed later) the above program can be written as follows:
#include
main( )
{
for (i=l; i<=1000; i++) printf ("HELLO WORLD");
;" }
This program is just one liner but prints HELLO WORLD 1000 times.. Such is the power of control statements.
Consider another class of problems where you wish to execute certain statement only when some condition is true. Control statements allow you to select or reject statements to be executed depending on the truth value of a conditional expression.
But for the control statements a programming language would have only limited
application.
C language provides 4 types of control statements, which are sufficient to form any desired form of execution control. These control statements are:
a) Sequence control statements
b) Decision control statements or conditional statement
c) Case control statements
d) Repetition or loop control statements
|
|
Article Source :
http://www.articleseen.com/Article_Decision Making, Branching & Looping concept in c programming_81452.aspx
|
Author Resource :
learncprogrammgs offering c programming online,c programming for beginners, about for loop in c, decision making branching looping in c, c program code,for loop programs in c language , for loop code ,c language basics.
|
Keywords :
For loop program online, c programming for beginners, about for loop in c, for loop code, for loop example, odd number progra,
Category :
Reference and Education
:
Language
|
|
|
|