DCSA--Computer Programming :
Topics : Decision Making and Looping :
Question and answer : Category : LOOP :
# What do you mean by looping ? Describe two different forms of looping .
Ans : A loop is a sequence of instructions that is continually repeated until a certain condition is reached.
Two forms are ; 1. Entry-controlled loop . 2. Exit-Controlled loop .
Entry-Controlled loop : The control conditions are tested before the start of the loop execution.
If the conditions are not satisfied, then the body of the loop will not be executed.
Exit-Controlled loop : The control conditions are tested at the end of the body of the loop .
As result the body is executed unconditionally for the first time.
Loop Structure :
Looping Process :
1. Setting and initialization of a condition(counter) variable.
2. Execution of the statements of the loop.
3. Test for a specified value of the condition variable for execution of the loop.
4. Increasing or updating the condition(counter) variable.
MCQ : 1. a loop is a sequence or arrangement of
a) Variables b) Constants C) Instructions d) None of these .
2. In looping , a sequence of statements are executed until----
a) Some conditions for end of the loop are satisfied b) Only one conditions for end of the loop are satisfied.
c) Some variables for end of the loop are satisfied d) None of these.
3. In the entry-controlled loop , the control conditions are tested
a) Before the start of the loop execution. b) After the start of the loop execution
c) Some variables for end of the loop are satisfied . d) End of the loop execution.
4. In the exit-controlled loop, the control conditions are tested
a) At the end of the body of the loop b) After the start of the loop execution
c) Before the start of the loop execution d) None of these.
MCQ : While loop :
1. A while loop in C programming body of the loop or statements may be
a) A single statement or a block of statements. b) Only single statements
c) Only two blocks d) None of these.
2. A while loop repeatedly executes a target statement as long as a give
a) Condition is true b) Condition is false c) Both true and false is possible d) None of these.
3. In while loop when the Test-condition is tested and the result is false, body of the loop will be-
a) Printed b) Terminated c) Executed d) Skipped .
MCQ : For loop :
1. In for loop initialization of control variable using-
a) Assignment operator b) Relational operator c) logical operator d) None of these.
2. For loop is another -
a) Entry-controlled loop that delivers shorter loop control structure.
b) Exit-controlled loop that delivers shorter loop control structure.
c) Exit-controlled loop that delivers longer loop control structure.
d) None of these.
3. After execution of the body of the for loop , the flow of control-
a) Jumps back up to the increment/ decrement statement.
b) Jumps down up to the increment/ decrement statement.
c) Jumps back up to the assignment statement.
d) Jumps back up to the test-control statement. ## Show different types of looping in flowchart :
1. While loop . 2. Do-While loop. 3. For loop
1. While loop :
Basic syntax : While (Test conditions) {
statements;
}
Flow chart : Like entry controlled loop.
2. Do-While Loop :
Basic syntax : do {
statements ;
}
while (Test conditions);
Flow chart : Like exit controlled loop.
3. For loop :
Basic syntax : for (initialization, test-condition, increment/decrement) {
statements;
}
Flow chart :
a) Condition is true b) Condition is false c) Both true and false is possible d) None of these.
3. In while loop when the Test-condition is tested and the result is false, body of the loop will be-
a) Printed b) Terminated c) Executed d) Skipped .
MCQ : For loop :
1. In for loop initialization of control variable using-
a) Assignment operator b) Relational operator c) logical operator d) None of these.
2. For loop is another -
a) Entry-controlled loop that delivers shorter loop control structure.
b) Exit-controlled loop that delivers shorter loop control structure.
c) Exit-controlled loop that delivers longer loop control structure.
d) None of these.
3. After execution of the body of the for loop , the flow of control-
a) Jumps back up to the increment/ decrement statement.
b) Jumps down up to the increment/ decrement statement.
c) Jumps back up to the assignment statement.
d) Jumps back up to the test-control statement. ## Show different types of looping in flowchart :
1. While loop . 2. Do-While loop. 3. For loop
1. While loop :
Basic syntax : While (Test conditions) {
statements;
}
Flow chart : Like entry controlled loop.
2. Do-While Loop :
Basic syntax : do {
statements ;
}
while (Test conditions);
Flow chart : Like exit controlled loop.
3. For loop :
Basic syntax : for (initialization, test-condition, increment/decrement) {
statements;
}
Flow chart :
Welcome.
ReplyDelete