Skip to content

Instantly share code, notes, and snippets.

@tripdog
Last active June 12, 2021 22:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tripdog/afb45f54bfb825fd5d51cb349999b8d6 to your computer and use it in GitHub Desktop.
Save tripdog/afb45f54bfb825fd5d51cb349999b8d6 to your computer and use it in GitHub Desktop.
Basic For Loop Examples

Basic For Loop Examples

Count to 100 by only odd numbers

for (let x = 0; x < 100; x++){
    if ((x % 2) !== 0)
        console.log(x)
}

Count To 100 By 5

for (let i = 0; i < 100; i += 5){
console.log(i)
}

Count down from 10 to 0

for (let i = 10; i > 0; i-- ) {
    console.log(i)
}
@tripdog
Copy link
Author

tripdog commented Jun 10, 2021

For loops!

They take time to get used to when you're a beginner. Hopefully somebody will see these, try them, and get the hang of it. The solution for counting to 100 by using only odd numbers was kind of surprising. Learning, growing, coding!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment