Loops/Wrong ranges: Difference between revisions

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.
{{errors}}
1. ⟳ ic:(-2 |..| 2).new_cursor - 1 ¦ do_nothing ⟲
Produces a Design by Contract precondition error.
Hint: Reverse the cursor and step positive or do not try to step negative.
(This is a bug in the logic and not the precondition)
 
Produces a=== Design by Contract preconditionErrors 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 ⟲
This has the same problem. It is a bug in the logic and
not in Eiffel or the precondition.
 
=={{header|Factor}}==
Anonymous user