For Loops

Owen Abbott
2 min readDec 27, 2020

--

Twice during my time in the bootcamp, I solved a problem using a for loop and was faced with criticism.

Once was during the tech assessment to get into the bootcamp. Flatiron boasts about having a very, very low acceptance rate. They only accept like, six percent of applicants, they say.

However, the act of registering to just take a cursory look at their curriculum makes you an applicant. So, I imagine, plenty of non-interested people are considered applicants.

Anyway. They boast a low acceptance rate and make it look like they really vet people by having us go through a technical assessment before acceptance. I solved the technical problem with a for loop. The test instructor, because he’d never seen any student use one, said that “in the real world” people don’t use for loops.

I had a similar experience during the first learning module while in the bootcamp. I solved the mod 1 assessment using for loops. The coach didn’t know why my solution worked, and didn’t know what my code even was at first glance. I had to explain what temporary variables in the loop are, I had to explain how the loop worked. The coach passed me, but also told me that “in the real world” people don’t use them. The instructor told me that I did good, though.

Since graduating the bootcamp, I have seen more than one professional coder on my network offering bootcamp grads advice, and telling horror stories where they interviewed bootcamp grads who “didn’t even know” how to put together a for loop.

There seems to be a discrepancy between what bootcamp staff tell you is good practice ‘in the real world’ and what professionals in the ‘real world’ say is good practice.

So for my blog today, I’m showing you, dear reader, how to write a for loop.

In ruby, it’s simple.

for i in testArray,
do Thing
end

i is the temporary variable — it doesn’t need to be called “i”, it can be called anything. It is declared in the loop itself. The loop iterates through each element (which we referred to as “i”) in testArray and does whatever Thing you tell it to do.

In javascript, it looks slightly more confusing.

for (let i = 0; condition; i++){
Thing
};

You don’t need to write ‘let’ before declaring what i is in a javascript for loop, but if you’re in strict mode it will yell at you, so you probably should. I is defined usually as zero, and each time the condition is met, i is increased by one. The condition could be something like i < testArray.length to get the same effect as the ruby for loop above.

Congratulations, now you know how to use for loops. Don’t let anyone tell you that it’s unprofessional to use loops, because they’re incredibly common and basically a building block of everything.

--

--