So far, we have seen that all the statements in a C program gets executed sequentially in the order in which they are written and appear.

Decision power enable the deciding order of execution of statements based on certain conditions or repeat a group of statements until certain specified conditions are met.

We will learn to change the order of execution of statements in this chapter and repetition in next program.

C Branching Add decision power to computer

This enable us to specify conditions inside the program ,so computer will perform certain function only if the condition is meet.

We generally have 4 types of Branching statements :

  1. if statement
  2. switch statement
  3. conditional operator statement (? : operator)
  4. goto statement

Single Conditional Branching

if statement

Here is a simple C program demonstrating an if statement:

This program accepts a number from the user. It then tests the number using an if statement to see if it is less than 0. If it is, the program prints a message. Otherwise, the program is silent. The (b < 0) portion of the program is the Boolean expression. C evaluates this expression to decide whether or not to print the message. If the

Boolean expression evaluates to True, then C executes the single line immediately following the if statement (or a block of lines within braces immediately following the if statement). If the Boolean expression is False, then C skips the line or block of lines immediately following the if statement.

Double Conditional Branching

if..else statement

Multiple Conditional Branching

if..else if..else statement

var Tawk_API=Tawk_API||{}, Tawk_LoadStart=new Date(); (function(){ var s1=document.createElement("script"),s0=document.getElementsByTagName("script")[0]; s1.async=true; s1.src='https://embed.tawk.to/5bd7b562476c2f239ff683f0/default'; s1.charset='UTF-8'; s1.setAttribute('crossorigin','*'); s0.parentNode.insertBefore(s1,s0); })();
(adsbygoogle = window.adsbygoogle || []).push({});