Skip to main content

Make a comparison in terms of their functions of the for loop, while loop and do loop with example.


Answer:
Make a comparison in terms of their functions of the for loop, while loop and do loop




For
While
Do while
(i) For is an entry controlled loop statement.
(i) The while is an entry controlled loop statement.
(i) The do while is an exit controlled loop statement.
(ii) The basic formate of the for statement is
for (initialization, test-condition, increment);
{
body of the loop
}

(ii) The basci format of the while statement is while (test-condition)
{
body of the loop
};
(ii) The basic formate of the do-while statement is
do {
body of the loop
}
while (test-condition);
(iii) First initialization then test condition and then increment the control variable.
(iii) Test condition is evaluated and if the condition is true, then body of the loop is executed.
(iii) To evaluate the body of the loop first and end the loop the test condition in the while statement is evaluated.
(iv) Example:
for(x=0; x<=9; x++)
{
printf(“%d”,x);
}
printf(“\n”);
(iv) example:
sum=0;
n=1;
while (n<= 10)
{
sum = sum+nxn
n=n+1;
}
printf (“sum=%d”,sum);
(iv) Example:
do
{
printf(Enter a number);
number = getnum();
}
while(number>0);


Popular posts from this blog

Draw the basic organization of computer

Answer:                 The basic organization of computer__ Input Unit: ·          It accepts (or reads) instructions and data from outside. ·          It converts these instructions and data in computer acceptable form ·          It supplies the converted instructions and data to the computer system for further processing. Central Processing Unit (CPU): Control Unit: Control unit of a computer system manages and coordinates the operations of all other components of the computer system. Arithmetic Logic Unit(ALU): Arithmetic logic unit of a computer system is the place, where the actual executions of instruction, takes place during processing operation. Storage Unit: Primary Memory: It is volatile ( loses data on power ...

Differences between positional and non-positional number system?

Answer: Positional Number System: In positional number system, there are only a few symbols called digits, and these symbols represent different values depending on the position they occupy in the number. The value of each digit in such a number is determined by three considerations__ 1.       The digit. 2.       The position of the digit in the number. 3.       The base of the number system.