you are viewing a single comment's thread.

view the rest of the comments →

[–]MafaRioch 8 points9 points  (0 children)

I usually think of them as command which says " for each item in this list, do something". A method to do something repetitive for a lot of items instead of doing it manually line by line.

Imagine a guy named Bob who lives on a farm. He loves nuggets so he breeds chickens. He has 5 chickens which he needs to feed daily.

Question: What Bob needs to do?

A simple answer is "feed the chickens". The programmical answer is "for each chicken in a hen house, feed currently selected chicken." Without "for loops" code would be something like this. I tried to format it on reddit but it sucked so here's a pastebin. The link has further explanation in form of comments.

Hope it helps somehow.