DEV Community

Cover image for Understanding Loops - A Tangible Example
Tyler V. (he/him)
Tyler V. (he/him)

Posted on

1

Understanding Loops - A Tangible Example

This is a submission for DEV Computer Science Challenge v24.06.12: One Byte Explainer.

Explainer

Image of a short JavaScript function that we'll be stepping through in the guide. First, it sets the age variable to 25 (or whatever your age is), then has a comment to grab a piece of paper and draw a birthday cake. Then there's a short while loop that while age is greater than 0, draw a candle then subtract 1 from the age variable. Outside of the loop is another comment that it's celebration time.

1 - Setup

Get paper, draw a cake, and set age to your age.

2 - Do Loop

age isn't 0, so draw a candle and subtract 1 from age.

3 - Checkup

Is age still greater than 0? Go to step 2
Otherwise, go to 4.

4 - πŸŽ‰

Celebration time!


Additional Context

I didn't include markdown in my count - ended up at 248 according to VS Code:

Image of text highlighted and showing 248 characters were selected

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (0)

Sentry image

See why 4M developers consider Sentry, β€œnot bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay