19
I avoided loops for ages (they confused me) but not anymore.
My code is half as long and way easier to change.
3 comments
Log in to join the discussion
Log In3 Comments
kevin1101mo ago
Yeah that "half as long" thing is so real. I was copying and pasting the same line of code like ten times before. Learning loops just meant changing one number instead of editing every single pasted line. Saves a dumb amount of time.
9
the_nathan1mo ago
For loops in JavaScript can turn twenty lines into three! I remember a project where I needed to print numbers 1 to 100. Writing each line would be crazy, but a for loop did it in four lines. That means changing one variable updates everything at once. The time saved is huge because you avoid mistakes from copy-pasting. Loops make code simpler and faster to fix.
4
pipera501mo ago
My first real project had like 30 nearly identical divs. Manually updating the class name was a nightmare. I finally tried a loop and cut it down to maybe five lines, just like @the_nathan said. It felt like magic, and I never went back to copy-pasting code blocks.
6