CONDITIONAL STATEMENTS IN C

Om Sharma
2 min readJul 2, 2020

To control the flow of the execution of programs, the ‘C’ language provides very powerful conditional and unconditional statements . The ‘C’ language supports many conditional statements like :
Ø If
Ø If-else
Ø switch

Loop control statement is :

Loop control conditional statements are :

These statements enable us to change flow of the program. Most of the programming tools use the if statement to make decisions. If the expressionis true then the statements enclosed in the braces, are executed. If the expression is false, then the statements enclosed in the braces, are not executed, only the statements which exist outside the braces, are executed.

This statement allows decision to be made by evaluating a given condition as true or false. The keyboard if tells the compiler that it is a decision control instruction.The condition if is always enclosed within a pair of parenthesis. The relational operators allow us to compare two values to see whether they are equal to each other, unequal, greater or less than the other. The general form of if statement looks like this :

If the expression is true then the statements enclosed in the braces, are executed. If the expression is false then the statements enclosed in the braces, are not executed.

The if statement can contain another if….else statemet thus improving the flexibility of a programming tool.The statement whose object is if statement is a nested if statement .

if (expression 1 && expression 2 && expression 3 && expression 4)

Here , if expression is true, then code of the first block is executed, else second block is executed.

The control statement, which allows us to make a decision from the number of choices, is called a switch. With the help of switch and case statements we may choose any number of decisions, or more correctly a switch-case default, since the combination of these three keywords go together to make up the control statement.

The switch statement checks, whether an expression matches with number of integer or character constant.

In the nested switch statements, only one default case is used i.e, with the outer switch statement.

As a good ‘C’ programmer , avoid using goto statements. A goto statement is always followed by a LABLE. The lable may be an identifier declared, constant, character constant, or a string constant. LABLE does not allow any special characters, but numeric characters are allowed. A lable decides the position of the control to be jumped, and which is allowed by colon(:). A lable may be constant as well as variable.

Originally published at https://c-programmer-xp.blogspot.com.

--

--