CBSE Class 10 Computer Applications Question 13 of 26

Python Conditionals and Loops — Question 4

Back to all questions
4
Question

Question 4

Differentiate between for and while statements.

Answer

Difference between for and while statements in Python:

S.
No.
forwhile
1.for loop is used when the number of iterations are known beforehand.while loop is used when the number of iterations are not fixed and depends on a specific condition.
2.for loop is used for iterating over a sequence or a range.while loop is used for repeated execution based on a condition.
3.Syntax:
for <variable> in <sequence> :
    statements_to_repeat
Syntax:
while <logicalexpression> :
    statements_to_repeat