Computer Applications
Differentiate between for and while statements.
Python Control Flow
4 Likes
Answer
Difference between for and while statements in Python:
S. No. | for | while |
---|---|---|
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> : statementstorepeat | Syntax: while <logicalexpression> : statementstorepeat |
Answered By
1 Like