C
control statements in c | control statements
hi everyone welcome to coding idea
control statements in c
technologies this is Finn was in thelast session we discussed the basic
control statements so that is if
conditional control statement we
discussed now in this session we will
see how if-else conditional control
statement gets executed conditional
statement if-else conditional control
statement okay so the last class we have
seen already write the definition the
syntax and as well as the flow so now in
this case so once again the syntax and
all we are checking seeing here
conditional control statement that is
if-else what is the definition this is
if-else if-else conditional control
statement what is the syntax here a
syntax is if condition a block this is
if block statements these are true
statements and next one this is else
else block and these are failure messes
failure messes if condition is a true
then all the statements defined inside
the if block gets executed if condition
What are control statements?
is a false in the previous case we arenot printing any optional message if
condition failed but now using else
block we are printing optional messes
also depends on the true or false
conditions now two different blocks
execute right here it is so what is the
exact definition if else block right
here it is providing providing optional
information optional information to the
end user to the end user if condition
has failed
if
condition has failed in failure case
also we are providing information to the
end-user this is called if-else now see
the flow and here it is in the previous
case we are giving only statements we
are printing only statements if it is a
true now in case of false also we are
What are control flow statements?
printing the statements these statementswe are printing in case of false also to
true or false true or false now as usual
it will check the condition if condition
is a true if block statements execute
and control come to end if condition is
a false so then else block statements
execute and the control come to end so
depends on a condition
true or false either if block executes
or else block executes only one block
executes but not the both okay so one
example will see so what is that example
here this finding a number is a even
number or odd number program write a
What are examples of control structures?
program to check a number is even or oddsimple program using if-else so first we
have to read one number based on the
heading only we are writing the program
we need to check a number is even or odd
for that first input is very very
important here it is hash include
stdio.h main inside the main I am
declaring one variable N and we are
reading printf enter a number we are
reading how to read a scanf we are using
scanf percent is d
address of n address of n we are reading
the number after reading now we need to
check whether it is even or odd
condition we have to write what is that
even number the number which is
divisible by 2 so reminder operator we
are using n n is a number that what you
have read Maud Maud to write reminder
operator if n mod 2 equals to 0 this is
the condition if n mod 2 equals to 0 if
this condition is a true I am printing a
message this is even number n is even
number clearly I am printing percentage
D is even what is that percentage d n n
is a even number
What are selection statements in C?
suppose if condition is a false then weare printing odd number percentage d n
is odd number this is we are printing
now see how it executes observed n value
we are taking sir what is the N value
take any value for example 4 for mod 2
for mod 2 will give what 0 0 equals to 0
0 equals to 0 condition is a true it
returns 1 so it will print the N is even
number what is the N value 4 4 is the
even number message it will print for
example if you take n value is a 5 n
value is a 5 5 mod 2 value is a 1 5 or 2
value 1 1 equals to 0 condition false if
condition falls directly execute the
else block it will print that message
that 5 is odd see here it is asking
enter a number we are reading suppose if
it is a 17 17 is
odd 17 is odd so this is a message so
this is how to work with a if-else and
we will see one more example how it
executes here suppose in the Declaration
of if block in the Declaration of if
block if you do not specify the
statements in braces only first
statement is considered as if block
statement already we discussed in the
previous session what is the note in the
definition of if block if we do not
specify the statements using block
nothing but using braces only first
statement considered as if block
statement so based on this statement
right we are writing one program for
example here if condition and here we
are writing printf printf a message hi
What is control statement in C language?
we are writing and next else blockprintf hello we are writing hello we are
writing and next one printf one more
message we are writing for example bye
now here condition I am giving is 7
what is the condition 7 here we are not
specifying any braces while defining
this if else while defining this if else
so we are not specifying anything so now
observe here condition is a true or
false so this is if block this statement
comes under if block only first
statement and next only first statement
comes under else block if Blokhin else
block now condition is a true or false
condition is a true so it will print
that block message hi if if block
executes else block will not execute it
terminates it will omit the execution of
else block but here remember else block
means not both the statements hallo and
by only a first statement is a hello so
it will terminate only execution of
hello it will
not only execution of hello this is
considered as the outside statement it
is a free statement there is no relation
for the statement with if-else so it
will execute by it will print so what is
the output of this program hi and by
these two will print okay see what is
the output this one hi and by these two
will print okay and next next one
What are the different control statements used in C language?
for example sir I am writing thisstatement here so then what is the
output now what is the output right here
it is a providing error message at the
time of compilation this is Error error
message this is Error sir wiser
it is error it is showing error message
very clearly here it is at the if block
at the if block it is showing that error
message wiser why it is showing error
means analyze the program how the
program is going to compile just analyze
for example first compiler writing if
condition so whatever the statement you
have written followed by if block only
one statement is considered as a if
block statement just writer here this is
the block compiler will consider like
this if block is there next compiler is
looking for else block here in this
looking for else block but is it there
no it is not there so compiler is
thinking that else block is optional
block very very important thing for
every if condition else block is
optional if you just write only if block
no problem simple if already we
discussed in the last class right here
looking for else block but else block is
optional so compiler is thinking that
for the programmer writes there is no
need of writing else block so that the
programmer omits simple thing else block
next whenever the control come to here
whenever the compiler is looking this
statement then it is considered as a
what are control statements
outside statement to if block this isouter statement is a free statement of
if block if else so according to the
compiler up to here no error up to here
in the first statement no error second
statement no error next it is looking
for a course else block is not there
optional and next it is looking for
outer statement yes it is considered as
a hallow statement as an outer statement
of if else but next whenever the
compiler reaches this statement is it is
looking else block here for this else
block where is the if block where is the
if block if block is missing for this
else block if block is missing for if
block else block is optional is okay but
for else block if block is not optional
it is compulsory but where is the if
block it is not there so here it is
giving error message different types of
errors in some of the compilers it will
give misplaced else misplaced else or in
some of the compilers it will give else
block without if block else block
without if block different compilers
will give different types of error
messages in this line so once again
according to the compiler the first
statement of if block only first
statement here only first statement here
is considered as a if block statement
and next it is looking for else block it
is not there then it is considered as an
outer statement here also no problem but
whenever the compiler commands check
this else block now else
c language
block is present where is thecorresponding if block it is missing so
directly a compiler will give error
message here else block is present but
if block is not present so else without
if block that is not allowed in a
if-else conditional control statement so
this is how if-else blocks
execute in a C language okay so in the
next session we will see how if else if
later executes and how nested if
conditional control statement executes
okay for more articel

Post a Comment
0 Comments