Loops/Wrong ranges: Difference between revisions

Line 537:
-- Loops/Wrong ranges
do
⟳ ic:(-2 |..| 2) ¦ do_nothing ⟲ -- 2 2 1 Normal
⟳ ic:(-2 |..| 2).new_cursor + 0 ¦ do_nothing ⟲ -- -2 2 0 Zero increment
⟳ ic:(-2 |..| 2).new_cursor - 1 ¦ do_nothing ⟲ -- -2 2 -1 Increments away from stop value
⟳ ic:(-2 |..| 2).new_cursor + 10 ¦ do_nothing ⟲ -- -2 2 10 First increment is beyond stop value
⟳ ic:(-2 |..| 2).new_cursor.reversed ¦ do_nothing ⟲ -- 2 -2 1 Start more than stop: positive increment
⟳ ic:(2 |..| 2) ¦ do_nothing ⟲ -- 2 2 1 Start equal stop: positive increment
⟳ ic:(2 |..| 2).new_cursor - 1 ¦ do_nothing ⟲ -- 2 2 -1 Start equal stop: negative increment
⟳ ic:(2 |..| 2).new_cursor + 0 ¦ do_nothing ⟲ -- 2 2 0 Start equal stop: zero increment
Line 550:
</lang>
{{out}}
In this example, we are using the "symbolic form" of the Eiffel across loop, such as: ⟳ ¦ ⟲
 
In each case, we iterate over an INTEGER_INTERVAL (e.g. (-2 |..| 2), which represents a contiguous range of integers from a starting value to an ending value. The `ic' represents our integer value for each iteration. The call to `do_nothing' does exactly what you think--it does nothing at all because we are demonstrating the loop using various ranges and not what it processes on each iteration.
 
=={{header|Factor}}==
Anonymous user