#On looping

###`while...end`

If you need to `break` out of the loop, `while condition;code;end` will probably be shorter than `loop{code;condition||break}`.

The `;` before `end` is not always required, eg. `while condition;p("text")end`

`until c;...;end` is equivalent to `while !c;...;end` and 1 byte shorter.

###`redo`

When run, the `redo` command jumps back to the beginning of the block it's in.

When using `redo` in a lambda, you will have to move any setup variables to the arguments to avoid them being reset at every iteration (see examples).

###recursion

Recursion can be shorter is some cases. For instance, if you're working on an array element by element, something like `f=->s,*t{p s;t[0]&&f[*t]}` can be shorter than the alternatives depending on the `stuff`.

Note that per the [current consensus][1], if you're calling your function by name, you need to include the assignment (`f=`) in the byte count making all recursive lambdas 2 bytes longer by default.

###`eval`

If you need to run some code `n` times, you can use `eval"code;"*n`.

This will concatenate `code;` `n` times and run the whole thing.

Note that in most cases you need to include a `;` after your code.


##Examples

<!-- language-all: lang-ruby -->

###A lambda to print all numbers from `1` to `a` inclusive:

 ->n{i=0;loop{p i+=1;i<n||break}} # 32 bytes
 f=->n,i=1{i>n||p(i)&&f[n,i+1]} # 30 bytes
 ->n{i=0;while i<n;p i+=1;end} # 29 bytes
 ->n,i=0{p i+=1;i<n&&redo} # 25 bytes
 ->n{i=0;eval"p i+=1;"*n} # 24 bytes
 ->n{(1..n).map{|i|p i}} # 23 bytes

In this case, since the end-point is defined (`n`), the `(from..to)` loop is the shortest.

###Given a lambda `g` and a number `n`, find the first number strictly larger than `n` for which `g[n]` is truthy

 ->g,n{(n+1..1/0.0).find{|i|g[i]}} # 33 bytes
 ->g,n{loop{g[n+=1]&&break};n} # 29 bytes
 f=->g,n{n+=1;g[n]?n:f[g,n]} # 27 bytes
 ->g,n{until g[n+=1];end;n} # 26 bytes
 ->g,n{g[n+=1]?n:redo} # 21 bytes!

In this case, with an unknown end-point, `redo` is the shortest by far.

The `(n+1..Inf)` loop is equivalent to simply `loop`ing indefinitely but move verbose.

The `eval` method is not viable in this case because there is neither a defined end-point not an upper bound.


[1]: https://codegolf.meta.stackexchange.com/a/6940/77598