Python While Loop – Top 10 GATE CSE Questions with Answers
While Loop is very important for GATE CSE 2026 and Data Structure interviews. Let’s cover it with PYQ.
What is While Loop in Python?
While loop executes a block of code as long as condition is True.
i = 0
while i < 3:
print(i)
i += 1
For vs While Loop – GATE Point
For Loop: When iteration count is known.
While Loop: When condition based looping is needed.
GATE PYQ on While Loop
Q1. What is output?
x = 5
while x > 0:
print(x)
x -= 2
Ans: 5, 3, 1
Q2. Infinite Loop GATE Question 2021
while True:
print("GATE")
Ans: Infinite loop. To stop use break statement.
Time Complexity
While loop same as for loop – O(n) if runs n times. If nested O(n^2)
Conclusion
Practice while loop PYQ daily. Next post: Python List vs Tuple.
