Q2
What is the difference between a `for` loop and a `while` loop?
💬Answer
for: Iterates over a defined sequence (list, range, dictionary keys).while: Loops as long as a boolean condition remainsTrue.
# For Loop
for i in range(5):
print(i)
# While Loop (waiting for something to finish)
while True:
# Do health check
break
Related Python Questions
View All PythonQuestions →
Created by
Apurv Gujjar
DevOps & Cloud Engineer
Specialized in:DevOpsAWSGCPKubernetesTerraformDocker
View Portfolio