Search Placementyogi.com
 

Control Statements in C

The order in which the statements are executed are called control flow and the statements that are used to control the flow of execution of program are called control statements.

 

Above diagram shows the types of control statements present in C . Lets discuss each types in short quickly. 

Decision Control Statements in C:

The Decision Control Structures help you to perform actions based on a certain condition. 

  1. simple if or if else
  2. Nested if
  3. if-else-if Ladder

Let me  explain this with 2 real world examples:

1. If I feel Thirsty I drink water(or beer!) else I eat pizza!

2. Consider a situation where you get in to a fight with someone in college. 

Here is the decision making your mind does:

if ( The other person is weaker than me)

Beat the shit out of him!

else

Keep Quiet and move on !!

We face such situations every day in our life where we have to take decisions based on a condition. To implement such situations in C we use these Decision Making Control Structures.

Loop Control Statements:

The Loop Controls in C helps us to keep performing a task a certain number of times or until a certain condition becomes true.

The loop constructs available in C are:

  1. for loop
  2. while loop
  3. do-while

Example: Suppose, you are playing football,

You keep playing football until you feel tired. (while, Do while)

You keep playing football for 45 minutes continuously i.e. till half-time break (Similar to :for loop)

Case control statement 

Case control statement provides a way to select alternative out of several alternatives based on the choice. 

For example while withdrawing cash from ATM, We see lot of options on screen and we select cash withdraw option. Here each option is one case and we select one or more from these available cases. 

Banner to LogicGuns.com

Hide Page Information