Anonymous user
Loops/Wrong ranges: Difference between revisions
→{{header|Eiffel}}
Line 553:
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.
1. ⟳ ic:(-2 |..| 2).new_cursor - 1 ¦ do_nothing ⟲▼
Produces a Design by Contract precondition error.▼
In both instances (below), it is a precondition (Design by Contract) error to attempt to step negative in a positive stepping iterator. If you want to go backwards, then do a reverse call on the cursor and provide a positive step value. Even in the example provided, these are logic errors (bugs) and not real examples of valid code.
▲1. ⟳ ic:(-2 |..| 2).new_cursor - 1 ¦ do_nothing ⟲
2. ⟳ ic:(2 |..| 2).new_cursor - 1 ¦ do_nothing ⟲
=={{header|Factor}}==
|