PGoCareerGoCareer prep tools
Home
LoginSign up
  • Java
  • Python
  • AI
  • React
  • Angular
  • PHP
  • Node.js
  • SQL
  • DSA
  • HTML
  • CSS
  • JS
  • Spring
  • ML
  • MongoDB

Python · Theory

Loops in Python

← All stacks

Theory

21/268

Loops in Python

A loop repeats a block until you stop it. for walks each item in a list, string, or range. while repeats while a condition stays true. Pick for when you know the items. Pick while when you wait until something becomes false — like “until the user types quit”.

break leaves the loop. continue skips the rest of this round. pass does nothing. while True without a break or an update never ends — the terminal just sits there. That infinite-loop trap is worth one sentence in the viva.

Loops in Python — output — for 1 2 3 then while 3 2 1.

Exam tip

Define loop, then for vs while in one line each.

Example

# Loops
for i in range(1, 4):
    print("for", i)
n = 3
while n > 0:
    print("while", n)
    n -= 1

Loops in Python — output: for 1 2 3 then while 3 2 1.

Short notes

  • DefRepeat a block.
  • Rulefor = items. while = condition.
  • TrapInfinite while True.

Questions

1

Explain Loops as if you are teaching a junior — definition, then one tiny script.

2

What does the example print, and why?

3

What mistake do freshers make with Loops?

Previous← if-else in PythonNextfor Loop in Python →
P

GoCareerGo

Utilities · Preparation Hub · Resume · CV · Tools — one workspace.

Workspace

DashboardProfilePreparation HubResume builderCV builderCareer planning

PDF Tools

Merge PDFSplit PDFCompress PDFImage to PDFAll toolsJobs

Image & QR

Compress ImageResize ImageQR ScannerQR GeneratorBlogIT interview prep

Company

FAQFeedbackContactPrivacyTermsSitemap

© 2026 GoCareerGo. Keep moving forward.