Conditional Statements


We have studied some of the preliminary concepts in c programming, which are essential for writing simple programs involving simple arithmetic expressions in the previous chapter. All the statements in a program are executed sequentially from statement 1 to statement n. Some times we need to change the control flow in a program in order to make certain decisions. Any structured languages like C provides statements that can alter the sequence in which the instructions are executed. We have two types of control structures to change the flow of control namely Conditional Branching and Looping. In this chapter we discuss conditional statements in detail and looping we will discuss in the next chapter. The relational and logical operators are used to make conditional expressions. The result of conditional expressions is either true or false.

Relational Operators:

,<,>=,<=,==and != are the six relational operators used in C language. These all are binary operators which take two operands and give the result as either true or false. Using these operators we can make relational conditions to check the operands as greater than, lesser than or equal to etc.

                Ex: a>b   x<y  a==b etc.

Logical Operators:

Now let us try to solve the more complex the conditional statements using logical operators. C provides three logical operators viz. &&(AND), | | (OR) and ! (NOT) operators, which take relational expressions or other logical expressions as arguments and give the result as either True or false. By the use of logical operators we can improve the program logic and which may reduce the number of program statements or number of operations.

The if statement:

if is a conditional statement, used to make decisions. It has number of formats. We will discuss the different formats of if statement one by one.

Simple if


The statements will be executed only when the conditional expression gives true, otherwise those statements under if () condition will not be executed.

In case of more than one statement if we want to execute depending on condition. then we need to make it compound statement by enclosing the statements within a pair of braces{}.



conditional statements in c language Conditional Statements conditional statements in c program conditional statements in c examples all conditional statements in c control and conditional statements in c conditional and branching statements in c types of conditional statements in c example of conditional statement in c conditional statements concepts in c conditional statement control in c types of conditional control statements in c list of conditional control statement in c different conditional statements in c define conditional statements in c conditional decision making statements in c conditional statements in c programming example if statement conditional formatting chow conditional statements work in c conditional if statement in c conditional statements in c with examples conditional statements meaning in c conditional statements in c operators conditional statements structure in c conditional statements used in c various conditional statements in c


Please enter your comment!
Please enter your name here