C
Why do we use looping statement in C? | control statements in c -c tutorial
hi everyone welcome to coding idea
c tutorial
technologies this is inverse so today weare going to discuss about a nested
while loop in C language nested while
loop so first of all so what is a nested
while what is nested while so very
simple writing while loop writing while
loop inside another while loop inside
another while loop is called nested
while loop defining one while loop
inside another while loop is called a
nested while see the syntax is the
syntax observe while this is outer while
loop so in the outer while loop we are
writing outer condition outer condition
and inside we are writing another while
loop and here it is we are writing inner
condition we are writing inner condition
this is while loop so where we can write
the statements everywhere for example
here you can write a outer while
statements outer while statements you
can write here and inside the inner
while loop you can write an inner while
statements
Why do we use looping statement in C?
inner while statements and here it isoutside to inner while loop here you can
write outer while statements outer while
statements you can write so this is the
syntax of nested while loop this is
outer while loop and this is inner while
loop outer while loop executes based on
outer condition inner while loop
executes based on inner condition right
then how it executes
how it executes means first it will
check outer condition so suppose if
outer condition has failed then it will
terminate suppose if outer condition is
a true right so then the control move
inside it will print the outer while
loop statements first it will execute
outer while loop statements and next it
will check the inner condition Seraph
inner condition is also true the control
move inside it will execute inner while
loop statements after execution of inner
while loop statements then it will check
inner condition only what it will check
it will check inner while loop condition
because it is a loop as long as the
condition is a true it will repeat here
only sir suppose one second inner
condition is a true yes the control move
inside move inside it will print again
it will check so here only it will
repeat the control will check and
execute check and execute so suppose if
inner while loop failed then the control
come out of the inner while loop it will
execute outer while statements sir is it
end no once it reaches again it will go
and check out ur while loop if outer
condition is a true again the control
move inside same story right here it is
it will execute sir when the program
will terminate means only if outer while
condition has failed by the time only
then while loop will be terminated if
inner while condition has failed it will
continue with the remaining outer while
statement execution and once again it
will go and check out ur while loop this
what is control statement in c language
is syntax of nested while loop now Iwill explain the flow of nested while
loop see here this is the flow of nested
while flow so what is the
floo first start start it will check out
ER while loop first it will check out ER
while this is outer condition outer
condition sir if outer condition has
failed then the control mode to end this
is end start and end we are representing
with the help of parallelogram
if outer condition has failed if it is a
false then control directly come to end
sir suppose if outer condition is a true
if outer condition is a true what it
will execute outer while statements it
will execute first this is outer while
statements outer while statements
execute and next after execution of
outer while statement what it will check
inner condition it will check so here
inner condition it will check sir for
inner condition also true and false is
present yes suppose if inner condition
is also true if inner condition is also
true inner while loop statements execute
here this is inner while loop statements
after executing inner while loop
statements or what will happen it will
repeat here only again it will go and
check the condition here it will go and
check the condition once again again it
will check inner condition is a true or
false if it is a true again it will
control statements in c
repeat here only the loop will repeatsir when it will fail if inner condition
is false if inner condition is false
then remaining outer while loop
statements execute remaining outer while
loop statements execute these are outer
while
statements after execution of outer
while loop statements then what will
happen again it reaches end again it
will go and check out our condition so
here this is checking outer condition so
this is the syntax of nested while and
this is the flow of nested while
flowcharts very very important right so
this is a flow right now we will see one
example right that how a nested while
loop executes so now see the example
right how a nested while loop executes
one example main main I am declaring two
variables for example I value is a zero
I value zero comma J value zero so we
are writing outer while loop outer while
loop plus plus I is less than or equals
to five inside while loop plus plus J is
less than or equals to five inside we
are printing J value percentage D J
value outside also we are printing J
value only not the I value J value we
are printing J value how it executes
right see first I value is zero the
control come to here plus plus I that is
I value become 1 1 is less than or
equals to 5 condition true next the
control come inside plus + j J value 1 1
is less than or equals to 5 condition
true come inside it will print the J
value so what is a J value by the time 1
so in the output it will print 1
next after execution of this it will
repeat inner while loop only it will
repeat inner while loop next the J value
become two it will become two condition
true
What are the 3 types of control structures?,
come inside it will print J value twonext again it will repeat it will become
three condition true it will print three
next it will become four condition true
it will print four next it is a five it
will store five condition true next it
will become six whenever we are writing
six six is less than or equals to five
condition false then inner while loop
terminates the control come out of the
loop it will print the J value what is
the J value here six so it will print
six after printing now it will check
outer while condition it will check
outer while condition plus plus I I
value become 2 2 is less than or equals
to 5 come inside plus plus J so J value
becomes 7 J value become 7 7 is less
than or equal to 5 condition false while
loop will be terminated come outside it
will print the J value 7
next again it will repeat outer loop
here it is I value become 3 3 is less
than or equals to 5 condition true come
inside plus plus j j value become 8 8 is
less than or equal to 5 condition false
come out and it will print a J value
only 8 next again it will repeat right
outer loop I value become 4 condition
true and here it is a J value become 9
condition false but come out of that it
will print the J value 9 next outer loop
I value become 5 5 is less than or equal
to 5 condition true
come inside plus plus J Z value become
ten condition true come outside it will
print the J value ten next outer loop I
value becomes six now see six is less
than or equal to Phi condition false now
the program terminates so what is output
one to ten it will print this is how
write nested while loop executes okay so
we will see one more example see the
example here main main declaring two
variables
What are control statements?,
I value 0 J value 0 once again while buthere now I am taking post increment
value I plus plus is less than or equals
to 3 and inside while while here it is J
plus plus is less than or equals to 3 I
am not writing anything inside just
empty but at the end of the outer while
loop we are printing the final is a
values final I say values we are
printing I value ends a value a simple
program how it executes it is a post
increment so pre increment means what
first increases and substitutes post
increments means what first substitutes
and then increase now the post increment
means first 0 will be substituted later
the value become 1 but it will check the
condition with a substituted value only
what is the substituted value 0
condition true come inside J plus plus
means what it will substitute 0 but the
value become 1 empty body but it will
repeat with empty body only it will
execute next J value is 1 1 substitute
but the value become 2 condition true
next it will substitute 2 value become 3
2 is less than or equal to 3 condition
true next it will substitute 3 value
become
control statements
for but here it is a value 3 is lessthan or equal to 3 condition true next
it will substitute for value become 5 4
is less than or equal to 3 condition
false so come out come out now outer
while loop reputation I plus plus I
value it will substitute one value
become 2 condition true come inside J
value it will substitute 5 value become
6 condition false again it will repeat
it will substitute 2 value become 3 next
come inside it will substitute J value 6
but after substitution J value become 7
next it will repeat it will substitute I
value 3 but after substitution value
become 4 but see 3 is less than or equal
to 3 condition true come inside it will
substitute 7 value become 8 next again
it will repeat it will substitute for
value become 5 4 is less than or equals
to 3 condition false if outer while loop
has failed then completely the while
loop terminates so what are the values
of I and J finally so final
I value is a 5 final J value is a 8 so
What is control statement in C language?,
we should take care of that postincrement execution and pre increment
execution once again pre-increment means
write first it will increase and then
substitute if it is a post increment
means what first to substitute and then
increase that is the difference so final
output is a 5 and 8 so this is exactly
how nested while loop will execute ok in
the next session we will see how a for
loop executes okay so I hope you will
enjoy this video for more articel

Post a Comment
0 Comments