Page 274 - Computer Science Class 11 With Functions
P. 274
B. State whether the following statements are True or False:
1. The body of a loop should consist of more than one statement. __________
2. Statements in the body of the loop are indented at the level of indentation next to the level
at which the header is indented. __________
3. Statements in else block are executed when the loop terminates due to break statement. __________
4. The continue statement skips the body of the loop and the control moves out of the loop. __________
5. The statements in a while block will be executed as long as the condition specified in the
header clause of the while statement is True. __________
6. While specifying a range, it is optional to specify the start value. __________
C. Fill in the blanks.
1. Repeated execution of a sequence of statements is called __________.
2. The ____________ block of a for loop will be executed on successful execution of a for loop.
3. The ___________ statement terminates the loop unconditionally.
4. In a nested loop, the break statement appearing in an inner loop terminates only the _______ loop.
5. An execution of the loop's body is called an ________ of the loop.
D. Answer the following questions:
1. Differentiate between:
a. for loop and while loop
b. break and continue statements
2. How is the else clause in an if statement different from the else clause in a for loop?
3. What is an infinite loop? Explain with an example.
4. What is the error in the following code:
n =int(input("Enter a number"))
while n!=0:
count = count + 2
else:
print("Total Count"+count)
5. Rewrite the following code using for loop.
moon = 50
while(moon>0):
print(moon//5)
moon = moon - 5
Now, when you have two codes that achieve the same functionality (one using the for statement and the while
statement), which one will you prefer, and why?
6. Rewrite the following code using while loop.
for sun in range(5):
for moon in range(3):
if sun**moon>=5:
print(sun)
else:
print(moon)
Now, when you have two codes that achieves the same functionality (one using the for statement and the while
statement), which one will you prefer and why?
272 Touchpad Computer Science-XI

