30-Day Coding Challenge

Days 27, 28, & 29 — Breaking the Loop

Kester R.
DSV Logs!
Published in
2 min readAug 4, 2024

--

Photo by Author Via Microsoft Designer & Canva

The last week of my coding challenge is approaching its end. And looking at my progress, I find myself lacking, especially these three days: Days 27, 28, & 29.

I did the little I could on days 27 & 28 before I broke down once more on day 29. It’s hard being sick.

But don’t worry, I’m determined to break the unproductive loop. And that brings me to the highlight of these three days, where I broke literal loops in Python via the break statement.

It’s used alongside loop statements like while,if, and for statements to break the loop (and I repeated this phrase🙂).

Here’s a basic but bad example of how this works:

while True:
print('Being Unproductive')
break

# OUTPUT: Being Unproductive

Without the break statement, that would normally run forever and your entire memory would be unproductive, I guess?

I wondered why I didn’t know this sooner. It’s so useful to control the flow of code better.

The second, like it is continue.

Unlike break, it skips the rest of the code in a loop statement once the condition is met.

for numbers in range(1, 8):
if numbers == 5:
continue # It skips the rest of the loop body when numbers is 5
print('hey') # This means hey won't appear in the Output

print(numbers)

'''
OUTPUT:
1
2
3
4
6
7
'''

These two statements are obviously going up into my archive as “essentials.

On day 30, I met a turtle…

--

--

Kester R.
DSV Logs!

I'm a writer trying to do what he knows best - "hitting the keys on my keyboard"