This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
eiffel:faq:loops_across_iteration [2018/05/17 18:03] jonathan |
eiffel:faq:loops_across_iteration [2018/05/17 18:08] (current) jonathan |
||
---|---|---|---|
Line 1: | Line 1: | ||
====== Eiffel Loops and Iteration ====== | ====== Eiffel Loops and Iteration ====== | ||
- | * {{ :eiffel:faq:faq:eiffel_loops_iteration.pdf |Eiffel Loops (with from) and Iteration with "across"}} | + | * {{ :eiffel:faq:faq:eiffel_loops_iteration.pdf |Eiffel Loops (with "from") and Iteration with "across"}} |
* [[eiffel:videos;larry-rix|Short Videos on Iteration]] | * [[eiffel:videos;larry-rix|Short Videos on Iteration]] | ||
+ | |||
+ | ===== Loop ===== | ||
+ | |||
+ | <code eiffel> | ||
+ | from | ||
+ | i := 0 | ||
+ | n := 10 | ||
+ | invariant | ||
+ | n | ||
+ | until | ||
+ | i >= 10 | ||
+ | loop | ||
+ | i := i + 1 | ||
+ | variant | ||
+ | n-i | ||
+ | end | ||
+ | </code> | ||
+ | |||
+ | ===== Iteration with across ===== | ||
+ | |||
+ | <code eiffel> | ||
+ | across list_of_customers as customer loop | ||
+ | Io.put_string (customer.item.name) | ||
+ | Io.new_line | ||
+ | end | ||
+ | |||
+ | |||
+ | across 1 |..| 5 as it loop | ||
+ | Io.put_integer (it.item) | ||
+ | Io.new_line | ||
+ | end | ||
+ | </code> |