HitBrother

Control Statements Or Conditions In C Language

       Control Statements Or Conditions

1. Condition or Selection or Decision Control Statement

2. Switch case Control Statement

1. Selection Statements (Decision Control Structure):-

Selection statement allows the program to choose any one path from different set of paths of execution based upon the outcome of an expression or the state of a variable.

a) if
b) if else
c) nested if else
d) if-else-if

(a) Syntax of if
if(condition)
{
Statements;
}

(b) Syntax of if else
if(condition)
{
}
else
{
}

Advertisement

(c) Syntax of Nested if else
if(condition)
{
if (condition)
{
}
else
{
}
}
else
{
if (condition)
{
}
else
{
}
}

(d) Syntax of if-else-if Ladder
if(condition1)
{
}
else if (condition2)
{
}
else if (condition3)
{
}
else
{
}

'); var s = document.createElement('script'); s.type = 'text/javascript'; s.async = true; s.src = 'https://ad.admitad.com/shuffle/289c251618/'+subid_block+'?inject_to='+injectTo; var x = document.getElementsByTagName('script')[0]; x.parentNode.insertBefore(s, x); })();

2. Switch Case:-
switch(expression)
{
case
statement 1 sequence;
break;
case 2:
statement 2 sequence;
break;
case 3:
statement 3 sequence;
break;




case n:
break;
default :
default statement sequence;
}

Decision and Switch Case control statements allow the computer to take a decision as to which statement is to be executed next.

Common programming errors: –

1. The if statement does not include the word then. For this reason, it is an error to write:

if(condition) then
Statement;


2. In the if statement, the condition must be enclosed in parenthesis. Thus, it is an error to write:

if condition
statement;


3. In the if statement, no semicolon follows the word else. For this reason, it is logical error to write.

Now false statement will always execute

if(condition)
true statement;
else;
false statement;

4. Using a single equal sign = (for comparing) instead of a double equal sign = = will be
considered as logical error.
5. In a switch, the integer expression that follows switch must be enclosed in parenthesis. Thus it
is an error to write

switch i
{
………
………

}

Advertisement