Basic Algorithm Scripting - Chunky Monkey STOOPID LOOPIN'

Tell us what’s happening:
My code passes and I’m decently happy with the brevity of it. I wanted to use a for loop on this one. Up to this point, all of my for loops have looked something like for(let 1 = 0; i < arr.length; i++)

After some thinking, ended up with this for loop:
for (let i; arr.length > 0; i)

Would this be considered bad practice? I mainly ask this because I don’t refer to i at all in the loop. It’s just there to fill out the syntax. Was there a better way I could have written this specific for loop?

Your code so far

  // runs as long as the original array still has stuff in it
  for (let i; arr.length > 0; i) {

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ Safari/537.36

Challenge: Basic Algorithm Scripting - Chunky Monkey

Link to the challenge:

You could use a while loop instead?

1 Like

Why do you want to use for loop in the first place?
I asked about situations like this months ago here. Was told that it is bad practice to do stuff ‘just to fill out the syntax’

AH! haha, that’s exactly it

while (arr.length > 0) {

much better. Thanks!

EDITS: I’m terrible at formatting these posts.
EDIT: got my hand slapped. sorry for posting solutions.

Please don’t post full solutions.

apologies. that makes sense.

That means that yes, you shouldn’t be using a for loop.

The ‘why’ is basically that the more code you write, the more bugs you will have. If there is code that isn’t helping you get the job done, then its only providing potential bugs and nothing else.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.