Chapter 9 Looping Statements
Brain Developers
A. Fill in the blanks:
1. __________ means repeated execution of statements for fixed number of times in a program.
2. The ______________ variable keeps track of the number of times a process is executed.
3. The control variable is assigned an ______________ and __________________ value in FOR…NEXT statement.
4. FOR statement is always used along with the _______________ statement.
5. All the statements, which are to be executed in a loop, come in between ____________ statements.
6. The ______________ statement increments/decrements the value of the control variable.
7. ASCII Character ____________ can also create a Beep sound.
Answer:
1. Looping means repeated execution of statements for fixed number of times in a program.
2. The Counter variable keeps track of the number of times a process is executed.
3. The control variable is assigned an Initial and Final value in FOR…NEXT statement.
4. FOR statement is always used along with the NEXT statement.
5. All the statements, which are to be executed in a loop, come in between FOR…NEXT statements.
6. The STEP statement increments/decrements the value of the control variable.
7. ASCII Character 7 can also create a Beep sound.
B. State True or False:
1. Looping technique reduces the number of instructions. (True)
2. FOR statement increments the value of the control variable by one. (False)
Correct Answer: NEXT statement increments the value of the control variable by one.
3. The same control variable can be used in different loops. (False)
Correct Answer: The same control variable cannot be used in different loops.
4. In Nested Loop, the outermost loop will be executed first, before the inner loop. (True)
5. There can be maximum of 9 loops within a loop. (True)
6. WEND clause is used for FOR statement. (False)
Correct Answer: WEND clause is used for WHILE statement.
7. STEP value can never be negative. (False)
Correct Answer: STEP value can be negative or positive.
C. Application Based Questions:
1. Ritu is making a program using FOR…NEXT statement. She wants to give increment to the counter by the value 5 but she is not able to apply the clause. Which clause will you suggest her to use with FOR…NEXT?
Answer: She can use STEP 5 clause to use with FOR…NEXT.
2. Raman’s teacher asked him to name the variable, which keeps count of the number of repetitions performed in a loop but he is unable to recollect the same. Help Raman to answer this query.
Answer: Counter Variable/Control Variable
3. The teacher asked Priya to make a program and print the series 2, 5, 10, … 101. She wants that the program should run for 10 times. What logic will you suggest her to apply to get the desired output?
Answer:
FOR J = 1 To 10
I=1, N = 12 + 1
NEXT
D. Multiple Choice Questions:
1. Which variable keeps track of the ‘number of times’ a particular instruction has been executed in a loop?
a) Control
b) NEXT
c) FOR
Answer: a) Control
2. Which value is optional and can either be positive or negative?
a) FOR
b) STEP
c) NEXT
Answer: b) STEP
3. Which statement combines the initialization and checking steps of counters in a single statement?
a) DO
b) WHILE
c) FOR
Answer: b) WHILE
4. Which statement gives the increment to control variable, and directs the program control back to FOR statement.
a) NEXT
b) FOR
c) STEP
Answer: a) NEXT
5. Which statement shifts the control back in the WHILE statement?
a) WHILE
b) WEND
c) DO
Answer: b) WEND
6. Which command plays music in the background in QB64?
a) MB
b) MF
c) T
Answer: a) MB
E. Answer the following:
1. Explain the term looping.
Answer: Looping means repeated execution of a statement or a set of statements. It reduces the number of statements to be written in a program.
2. Define the FOR…NEXT looping statement.
Answer: FOR…NEXT statement is used when a group of statements is to be executed a specific number of times. Control variable is assigned an initial value and a final value with FOR statement. The NEXT statement increments the value of control variable by one and transfers the control back to the FOR statement.
3. What is the use of STEP statement in FOR…NEXT?
Answer: By default, the NEXT statement increments the value of the control variable by 1, but we can increase or decrease the value as per our choice using STEP statement. STEP value is optional and can either be positive or negative.
4. Describe the term nested loop.
Answer: The use of a loop statement within another loop statement is known as nested loop. For example, the FOR…NEXT which lies outside or encloses the second FOR…NEXT statement is called Inner Loop. The one, which lies inside is called Outer Loop.
5. How is WHILE…WEND loop different from DO UNTIL loop?
Answer: WHILE…WEND statement is executed repeatedly while a given condition remains true, whereas DO UNTIL statement is executed while a given condition remains false or becomes true.
6. Which variable stores the sum of the numbers entered during the execution of a loop?
Answer: Accumulator stores the sum of the numbers entered during the execution of a loop.
7. What is the function of GOSUB statement?
Answer: GOSUB statement is used to transfer the program control from one statement to another in a program. It is similar to GOTO statement, except when it encounters a RETURN statement, the program returns back to the GOSUB command.
8. What is the difference between Play and Beep statement?
Answer: The PLAY statement is used for playing musical notes in QB64. It can play one note at a time using different string characters. Another way to produce sound in QB64 is through BEEP statement. This statement can be placed anywhere in the program to alert the user that an error has occurred.
Thanks
ReplyDeleteYou
Welcome! Do share our website with your friends...
Delete