190 Programming and Data Structures
Explanation In the above program variable % a ' is initially 1 and * s ' is 0. Value of variable x i ' is
read which determines the final step of the series. In the do - whi le loop variable ' a ' is printed, added
to variable 1 s ', and then increased. This loop is continuously executed till ' a ' equals to the entered
number % i '. The output provides the summation of 1 to the entered number. Here, the entered number
is 5. Hence, sum from 1 to 5 is 15.
6.6 THE do-while STATEMENT WITH while LOOP
The format of do-while with multiple while statement loop is as follows.
do while(condition)
{
statement/s;
}
while (condition);
6.79 Write a program to use while statement in do-while loop and print values from 1 to 5.
# include <stdio.h>
# include <conio.h>
void main ()
{
in t x=0;
c lr s c r ();
do while (x<5)
I
AT++,*
printf (“ %d",x);
I
while(x<l);
OUTPUT:
1 2 3 4 5
Explanation The speciality of using the second while loop in the above program is to know that the
programmer can take the second w hile loop. Though the above program can run with the single
while statement
SUMMARY
This chapter deals with the loops that are to be used in the C programs. The scope of the various three
loops such as a) the for loop,b) the while loopc)the do-while has been narrated in detail in this
chapter. Perhaps this is the chapter where number of solved programs on these loops have been given
for the benefit of the programmer. Also examples on n ested loops have also been given in a simple
language and in depth. The information on breaking the loop and continuing the same is also
elaborated in detail together with examples.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.142.250.203