Tree @master (Download .tar.gz)
- ..
- 2014-02-03
- 4d-chess.md
- a-small-haskell-record-complaint
- cherenkov.md
- codata
- commonplace
- daemontools.html
- daemontools.md
- data-files-and-backpack.md
- distributed-git.md
- file-system
- formats.md
- higher-rank-trait-bounds.md
- idiomaticity.md
- in-defense-of-hm
- madlibs-intro.md
- madlibs-ml.md
- madlibs-scheme.md
- multiwhile.md
- orwell.md
- resources-laziness-and-cps.md
- script-based-data-analysis
- semigroup.html
- semigroup.md
- sexprs.md
- shift-resolve-parsing.md
- some-rust-errors.md
- static-versus-dyn
- tansu
- tc-post.md
- tc-post.md.bak
- telml.md
- typeclasses.md
- writer-leak.md
multiwhile.md @master — view markup · raw · history · blame
I read a paper recently that described a new looping construct. This
is admittedly pretty weird: we've pretty much settled on looping
constructs in imperative languages by now, and with a few exceptions
I don't see much change. You've got your while
and (increasingly
rarely) your do while
loop, which moves the test around:
cond -> true
-----------------------------------------------------------
while (cond) { body } -> body; while (cond) { body }
cond -> false
-------------------------------------
while (cond) { body } -> ()
cond -> true
------------------------------------------------------------------
do { body } while (cond) -> body; do { body } while (cond)
cond -> false
------------------------------------------
do { body } while (cond) -> body
We also have the nice scaffolding provided to us by for
loops, which
are nice sugar for while
loops:
for (init, iter, cond) { body } => init; do { body; iter } while (cond)
and we have flavors of foreach
loops, which add awareness of some
underlying iterator protocol or collection type, which introduces an
element of binding
foreach (x in coll) { body } => coll.iter(); while (coll.has_next()) { x = coll.next(); body }