Control Statements Or Conditions In C Language 0 918

Control Statements Or Conditions In C Language 0 919

       Control Statements Or Conditions

1. Condition or Selection or Decision Control Statement

2. Switch case Control Statement

loop

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
{
}

(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
{
}

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
{
………
………

}

Previous ArticleNext Article
Indian Mirchi will serve you taste in Indian news, general knowledge and information. Hope you like the story I write here and expect your points of discussion to improve them and give the best chili test out of the story. I will write tutorials also that helps students. In case you are looking for any specific information then share me in the comment.

Send this to a friend