Dont Need For Loop

Based on a side conversion EvidenceDiscussion, perhaps we don't need a dedicated FOR loop construct built into the language. It can be a library function, and syntax optimized for such looping functions gives us other possible short-cuts.

[Under Construction]

As far as FOR loops, like I mentioned elsewhere, a simple base library function used inside a WHILE may also suffice:

  while(for(&i, from=1, to=400, step=2)) {...}  // "full" keyword version
  while(for(&i, 1,400,2)) {...}  // positional version 

[How would such a library function work? The state of i needs to be carried somehow, and it isn't passed into for(). How's that state passed? -DavidMcLean?]

You are correct; I adjusted it.

[Aha. Yep, that version will work, although it does demand the language provide at least explicit support for pass-by-reference, a feature I'd typically prefer to avoid in favour of purely providing pass-by-value-where-the-value-might-be-a-reference as most OO languages currently do. Still, no show-stoppers; that's a perfectly fine design. -DavidMcLean?]

Note that in some languages, you declare pass-by-reference on the definition side such that we may not need to see "&". Also, if the language makes "while" implicit, we'd have shorter ways to "custom" or library-based loop functions. (EditHint: consider forking to another topic.)

      x > y {...}  // a language where "while" key-word not needed: [Boolean expression] {...}
      while(x > y) {...}  // filler "while" function for backward compatibility
      for(i, 1, 400) {...}  // A compact for-loop construct using the "for" function.
      for(i, from=1, to=400) {...}  // key-word parameter version (some langs allow both variations)
      miffle(a, b) {...} // We can make custom loop functions.
      while (miffle(a,b)) {...} // traditional version of the above line; would still work.

Note that this is a relatively minor issue. However, if somebody considers designing a new language, this is an idea to float.


EditText of this page (last edited October 17, 2014) or FindPage with title or text search