liveBook · Manning

Continuous improvement

As explained in The Well-Grounded Rubyist, Fourth Edition

Iteration is a technique in which a method call is supplemented with code that the method can invoke during its execution.

Iteration is a control-flow technique in which a method call is supplemented with code the method can execute during its own operation. Unlike conditional execution, it can pass control between the method and that code. section 6.0 section 6.3

In Ruby, an iterator is a method that expects a code block. The method can execute that block; inside your own iterator, use `yield` to call it. The block and `yield` are the core ingredients of iteration. section 6.3.1

loop { puts "Looping forever!" }

This block is passed to `loop`, which repeatedly executes its code. section 6.3.1

How The Well-Grounded Rubyist, Fourth Edition covers it

How deep it goes
Explains iterators, blocks, and yield, and contrasts iteration with execute-or-skip control flow.
Examples
Shows `loop { puts "Looping forever!" }` as a block passed to an iterator.
What you can do after
Build an iterator that invokes a supplied code block with yield.
How it connects
Links iteration to methods, code blocks, yield, and looping.

Also explained in

Compare how 30 books explain continuous improvement →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Well-Grounded Rubyist, Fourth Edition. The section links point to the parts of the book it draws on.