C Programming + Tutorials in C for Beginners

C Branching Statements

Home  »  C Programming  »  C Branching Statements

    In the term software or computer programming, it has a set of instruction (in simple or complex form) called program. These instructions are also called statements, which occurs sequentially or in either conditional way or in the iterative way. To handle such types of statements some flow controls required. These flow controls are called Control Statements

    In other words, the control statements are used to control the cursor in a program according to the condition or according to the requirement in a loop. There are mainly three types of control statements or flow controls. These are illustrated as below:


Branching Statement

  1. if statement
    1. Simple if statement
    2. if-else statement
    3. nested if statement
    4. else-if or ladder if or multi-condition if statement
  2. switch statement
  3. conditional operator statement


if statement

     The if statement is a powerful decision making statement which can handle a single condition or group of statements. These have either true or false action....
    When only one condition occurs in a statement, then simple if statement is used having one block.

if-else statement

     This statement also has a single condition with two different blocks. One is true block and other is false block...

Output is as :
Enter the Number
This is Even Number

nested if statement

     When an if statement occurs within another if statement, then such type of is called nested if statement.

Output is as :
Enter the three Ages of Ram,Sham and Ajay
Ram is Youngest

Ladder if or else if statement

     When in a complex problem number of condition arise in a sequence, then we can use Ladder-if or else if statement to solve the problem in a simple manner.

The marks obtained by a student in 5 different subjects are input through the keyboard. The student gets a division as per the following rules:

=> Percentage above or equal to 60 - First Division
=> Percentage between 50 and 59 - Second Division
=> Percentage between 40 and 49 - Third Division
=> Percentage less than 40 - Fail



switch statement

     When number of conditions (multiple conditions) occurs in a problem and it is very difficult to solve such type of complex problem with the help of ladder if statement, then there is need of such type of statement which should have different alternatives or different cases to solve the problem in simple and easy way. For this purpose switch statement is used. .

Output is as :
Enter the Choice from Four Days...
S = Sunday
M = Monday
T = Tuesday
H = Thursday


Conditional Control Statement

     This statement is based on conditional operator. This statement solves the problem's condition in a single line and is a fast executable operation. For this purpose we can take combination of ? and :

<< Previous Topic
Next Topic >>

Next Post »


Click here for comments
1 August 2018 at 20:38 ×

Simple and easy to students

sumant kumar
25 August 2018 at 09:08 ×

thank you for sharing nice article in your blog
web programming tutorial

7 September 2018 at 08:51 ×

great content with simple language

Thanks for your comment