Find the First Negative Number
Beginner · Write the code · from Python break, continue, pass: Controlling Loop Flow
From the lesson: Python break, continue, pass: Controlling Loop Flow
You're searching through a phone book for your friend's number. Once you find it, do you keep flipping through every remaining page? Of course not - you stop. Or imagine you're reading a list of emails. You skip the spam and only read the real ones. These are everyday examples of controlling the flow of a loop.
Read the lessonUse a for loop with break to find and print the first negative number in the list. Print "Found: " followed by the number.
Expected output:
Found: -3numbers = [4, 7, 2, -3, 8, -1, 5]
# Find and print the first negative number using break
More break, continue, pass exercises
- Print Without VowelsBeginner
- Predict the OutputBeginner
- Fix the Bug: Sum Until NegativeBeginner
- Password Checker with for-elseBeginner
All Python exercises · 50 practice problems · Control Flow quiz