DEV Community

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

Posted on

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

Top comments (0)