C language - Class 9 : Control statements - Part 1 (If, if-else, nested if, else-if ladder)

preview_player
Показать описание
Control statements in C :

Decision making statements OR structures are also called as Control structures.
They are used when the programmer wants to check OR test a logical condition. For Ex : 3 Greater than 2
In decision making statements, a statement OR a group of statements are executed when condition is true. 
And we also write other statements when the condition evaluates to false.
Normally we make use of logical operators in the test conditions.

Control statements in C

if statement
if-else statement
nested if and nested if-else
else if ladder

if statement
if statement checks the given condition.
if test expression is evaluated to true, statements inside the body of if are executed.
if test expression is evaluated to false, statements inside the body of if are skipped.

Syntax:
if (test condition)
{
one or more
Statements ;
}

if else statement checks the given condition.
if test expression is evaluated to true, statements inside the body of if are executed.
if test expression is evaluated to false, statements inside the body of else are executed.

if (test condition)
{
one or more
Statements ;
}
else
{
one or more
Statements ;
}

Conditional Operator :
? : is called as Conditional Operator.
Syntax :
Exp1 ? Exp2 : Exp3;

Exp1 is evaluated. If it is true, then Exp2 is evaluated and becomes the value of the entire ? expression.

If Exp1 is false, then Exp3 is evaluated and its value becomes the value of the expression.

if (test condition)
{
if (test condition)
{
one or more
Statements ;
}

one or more
Statements ;
}

Nested if else
if (test condition)
{
if (test condition)
{
one or more Statements;
}
else
{
one or more Statements;
}
}
else
{
one or more
Statements;
}

Nested if else
if (test condition)
{
if (test condition)
{
one or more Statements;
}
else
{
one or more Statements;
}
}
else
{
one or more
Statements;
}

else if ladder :

if (test condition 1)
{
one or more Statements;
}
else if (test condition 2)
{
one or more Statements;
}
else if (test condition 3)
{
one or more Statements;
}
else if (test condition 4)
{
one or more Statements;
}
else
{
one or more Statements;
}

switch case :
switch case is like check for the match and execute a block.
So we give a value to a variable to match.
The switch statement tests the value of a given variable against the list of case values.
When a match is found, a block of statements associated with that case is executed.

switch (variable)
{
case (value 1) : one or more Statements;
break;

case (value 2) : one or more Statements;
break;

case (value 3) : one or more Statements;
break;

...

default : one or more Statements;
}

break :

break is a keyword that breaks out of the code block.
In this case, break prevents the program executing the code in all the other case statements.
An important thing to note about the switch statement is that the case values may only be constant integral expressions

ankpro
ankpro training
C#
C sharp
Bangalore
Rajajinagar
Selenium
Coded UI
Mobile automation testing
Mobile testing
JQuery
JavaScript
.Net
C
C++
Components of the .Net framework
Hello World
Literal
Keywords
Variable
Data types
Operators
Branching
Loops
Arrays
Strings
Structures
Enums
Functions
Рекомендации по теме
Комментарии
Автор

Thank you for watching. Cheers! would you mind hitting *_like_* button and *_subscribe_* to our channel!
That will be awesome. We would be grateful to you. And also share this video in your circle via whatsapp, facebook and twitter.
Link to subscribe the channel

AnkproTraining
Автор

Tqq sir.... first I saw the likes it is very less I thought this video's are when I listend ur video's it simply ausome tqqq sir....ur way of teaching is

preethiyadav
Автор

what if we put scanf(); before printf statement. will it still work?

RohitYadav-oedm
Автор

can you upload full c programming laguage of class 9.and help me in program making

saurabhmishra
join shbcf.ru