Decision Making in C Language

0 23

For Decision making In any programming language i think it in different way. Suppose, I garaged my car. My car is white color and car number is 131337 for sure.  I saw same 2 colored car are garaged there and i forgot which one is mine, lol. So i start looking at the number plate:

  1. If the car number is 131337 : This is mine.
  2. Else if car number 131336: Hmm, Very close
  3. Else: The search number is incorrect!

Let’s do a simple test to see how it works:

 

Nested Conditional Test

We also can do nested test. For example if a condition is true then test other things. Something like this:

 

C programming Switch Statement

Whenever i needed to test more than 6 or 7 condition i will obviously use switch statement. Writing many if statement can be very tedious. For this reason, switch statement is the solution.  The syntax is :

For switch we first need to declare a variable which will hold data or pre-defined to test. Let’s do a example which will same as the IF condition:

 

This is all about the C programming conditional for now!

Leave a comment