Introduction to Decision Control Structure in C

Decision !!!

we all need to alter our actions in the face of changing circumstances. If the weather is fine, then I will go for a stroll. If the highway is busy I would take a diversion. If the pitch takes spin, we would win the match. If she says no, I would look elsewhere. If you like this article, I would write the next edition. You can notice that all these decisions depend on some condition being met.

C language too must be able to perform different sets of actions depending on the circumstances. In fact this is what makes it worth its salt. C has three major decision making instructions—the if statement, the if-else statement, and the switch statement. A fourth, somewhat less important structure is the one that uses conditional operators.

In the programs written easlier we have used sequence control structure in which the various steps are executed sequentially, i.e. in the same order in which they appear in the program. In fact to execute the instructions sequentially, we don’t have to do anything at all.

By default the instructions in a program are executed sequentially. However, in serious programming situations, seldom do we want the instructions to be executed sequentially.

Many a times, we want a set of instructions to be executed in one situation, and an entirely different set of instructions to be executed in another situation. This kind of situation is dealt in C programs using a decision control instruction.

As mentioned earlier, a decision control instruction can be implemented in C using:

  • The if statement
  • The if-else statement
  • The conditional operators

Related Posts

  • 81
    It may so happen that in a program we want more than one statement to be executed if the expression following if is satisfied. If such multiple statements are to be executed then they must be placed within a pair of braces as illustrated in the below example. Example: The current year…
    Tags: executed, statement, program, condition, default, control, decision, learn, structure, write
  • 78
    Like most languages, C uses the keyword if to implement the decision control instruction. The general form of if statement looks like this: if ( this condition is true )       execute this statement ; The keyword if tells the compiler that what follows is a decision control…
    Tags: statement, condition, program, executed, operators, control, decision, instruction, learn, programming
  • 62
    The programs that we have learned/developed in this tutorial so far used either a sequential or a decision control instruction. In the first one, the calculations were carried out in a fixed order, while in the second, an appropriate set of instructions were executed depending upon the outcome of the condition…
    Tags: statement, control, executed, instructions, program, worth, perform, set, condition, programs
  • 59
    The if statement can take any of the following forms: if ( condition ) do this ; if ( condition ) { do this ; and this ; } if ( condition ) do this ; else do this ; if ( condition ) { do this ; and this…
    Tags: condition, learn, program, write, programming, tutorial
  • 56
    It is perfectly all right if we write an entire if-else construct within either the body of the if statement or the body of an else statement. This is called ‘nesting’of ifs. Let's have an example: /* A quick demo of nested if-else */ main( ) { int i ;…
    Tags: if-else, statement, program, condition, write, learn, tutorial, programming

Satya Prakash

VOIP Expert: More than 8 years of experience in Asterisk Development and Call Center operation Management. Unique Combination of Skill Set as IT, Analytics and operation management.

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: