For Loops using Modulus %

Al Heck
Aug 8, 2021

--

What if we wanted to count backwards to 0? We can do a for loop for this as well! Simply reverse the sequence.

We can also add the ability to print only evens as well. We need to use a modulous to check if it has a remainder. If we divide our number by 2 and it has a remainder, we will skip it.

To get odd numbers, check with 1 vs 0.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Al Heck
Al Heck

Written by Al Heck

Unity Developer and Software Engineer who loves making games with GameDevHQ

No responses yet

Write a response