3 ms·
.each isn't a looping construct. It is mapping function. Looping constructs allow control over the loop iteration. Mapping functions do not. People probably sh
by DannoHung 14y ago
.each isn't a looping construct. It is mapping function. Looping constructs allow control over the loop iteration. Mapping functions do not.
People probably shouldn't confuse them. Does Ruby actually have a looping function?
- chipotle_coyote 14y agoGoing out on a limb here, but I think "for" is a looping function.
- DannoHung 14y agoDoes it's invocation syntax differ significantly from the invocation syntax of other functions? Is there another function with the same invocation syntax as for? What are for's arguments? What is it's results? These are all relevant questions when determining if it is a function or not. Just the simple fact that loop control is determined by a boolean and requires state implies that for isn't really a function. For what it's worth, I think Zed has a point. If you're trying to introduce a broad array of concepts to a new a programmer, going with a mapping method associated with an iterable is kind of complicated if you want to explain the whole shebang. Compare map from Haskell, Lisp, Python etc with each. In each of those languages, you only need to introduce: 1) Named values (as variables, or not) 2) Functions 3) Lists 4) The idea that a function can take a function as an argument You do need all the additional stuff for each that he mentions. Similarly, in languages that make higher order functions more difficult, and have implicit state, for is an easier thing to explain.
- yxhuvud 14y agowhile, until and begin .. end while/until. And loop, of course.