You are on page 1of 4

Chapter: 12 Loop Constructs

Questions Provided by: Sir Mateen Prepared By: Hussain Mehdi

Short
Questions
Q: 1 Define loop. Write it types.
Answer: The type of control structure that is used to repeat a certain statement
several times.

Types:
 For loop
 While loop
 Do-while loop
Q: 2 Differentiate between for and whole loop.
Answer: The major difference between the for loop and the while loop is that the
for loop is used when the number of iterations is known, whereas execution is
done in the while loop until the statement in the program is proved wrong.
Q: 3 Difference between while and do-while loop.
Answer: The difference between while and do-while loops based on execution
speed is that a do-while loop runs faster than a while loop. The do-while is faster
because it runs the first iteration without checking the loop condition. In contrast,
the while loop checks the condition always.
Q: 4 Write three expressions of for loop.
Answer: In this loop, for is the keyword which cannot be used as a variable name
there are three conditions mentioned inside the loop.
Expressions:
 Initialization
 Condition
 Increment/decrement
Q: 5 Define Nested loop.
Answer: The loop in which a loop inside another loop is called nested.

Syntax:
for (initialization; Expression; Increment/decrement)
{
for (initialization; Expression; Increment/decrement)
{
Statement(s);
}
Statement(s):
}
Q: 6 Define the Goto statement and write its syntax.
Answer: The statement that slips the number of the by using unconditional
transfer control structure.

Syntax:
Label: Statement
…………………………
………………………...
Goto: label
Q: 7 What is a loop control variable?
Answer: A loop control variable is a variable whose value determines whether a
program exits a loop or continues executing the loop code. The classic example is
the counted loop or “for” loop.
Q: 8 Draw the flow chart of while loop?
Answer: Is on pg: 194 of textbook fig. 12.1
Q: 9 write the program to print the first 15 even numbers.
Answer:

You might also like