Note

If you cannot find what you are looking for. Please visit our sitemap

Thursday, 2 June 2016

ICS Notes Computer Science Part 2 Chapter 12 Loop Constructs of C Short Questions

ICS Notes Computer Science Part 2 Chapter 12 Loop Constructs of C Short Questions


Q 1. What is a loop?
Ans. The repeatedly execution of a statement or set of statement is called a loop. In loop the statement or set of statements executes for a number of times or until the condition remains true. The statement or set of statement that are executed repeatedly is called the body of the loop. Looping structures is also called iterative or repetitive structure.

Q 2. Why loops are used?
Ans. The repeatedly execution of a statement or set of statements is called a loop. In loop the statement or set of statement executes for a fix number of times or until the condition remains true. Loops are used to do similar or same tasks repeatedly.

Q 3. What are different types of loops available in C language?
Ans. In C language there are three types of loop statements

  • while loop
  • do-while loop
  • for loop


Q 4. What is while loop?
Ans. It is a conditional loop statement. It executes a statement or a set of statement repeatedly until the given condition remains true.
The syntax of while loop is
while (condition)
statement;

Q 5. What is do-while loop?
Ans. It is a loop structure that is used to execute a statement or set of statement repeatedly as long as the given condition remains true its working is similar to while loop but condition comes after the body of the loop.
The syntax of a do...while loop in C programming language is
do {
   statement(s);
} while( condition );

Q 6. What is the difference between while and do-while loop?
Ans. While Loop

  • Condition comes before the body of the loop.
  • If condition is false at beginning body of the loop dose not execute.
  • Semicolon (;) is not used at the end of the while statement.


Do-while Loop

  • Condition comes after the body of the loop.
  • The body of the loop is executed once even if the condition is false at the beginning.
  • Semicolon (;) is given at the end of the do-while statement.


Q 7. What is for loop?
Ans. 'for' is keyword of C language. 'for' statement is used as a loop statement. It is used to execute a statement or set of statement repeatedly for a specific number of times. It is also called counter loop.
The syntax of a for loop in C programming language is
for ( init; condition; increment ) {
   statement(s);
}

Q 8. What is nested loop?
Ans. A loop within the body of another loop is called nested loop. Any loop statement can be used with in the body of any loop statement. For example a while can be used with in the body of for loop. The nesting can be done up to any level. If the nesting level is increased the working of loop becomes complex.
The syntax for a nested for loop statement in C is as follows
for ( init; condition; increment ) {

   for ( init; condition; increment ) {
      statement(s);
   }

   statement(s);
}

Q 9. What is go to statement?
Ans. goto statement is used to transfer flow of control to a named label, It is an unconditional statement. The label should be in same function. The syntax of goto statement is
goto label;
               _________________
               _________________
               _________________
Label;

Written by: Asad Hussain

No comments:

Post a Comment