Loops/Wrong ranges: Difference between revisions
Content added Content deleted
Line 553: | 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. |
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) |
|||
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}}== |
=={{header|Factor}}== |