mirror of
https://github.com/EiffelSoftware/eiffel-org.git
synced 2025-12-08 15:52:26 +01:00
Added caveat concerning use of iteration form and altering structure.
Author:halw Date:2010-02-10T18:17:49.000000Z git-svn-id: https://svn.eiffel.com/eiffel-org/trunk@448 abb3cda0-5349-4a8f-a601-0c33ac3a8c38
This commit is contained in:
@@ -165,6 +165,10 @@ Notice also that the call "<code>print (ic.item)"</code>" accesses the current i
|
||||
|
||||
Concerning cursors, both ways of using the loop construct to traverse a structure employ a cursor. In the base form, the cursor is internal to the structure object. In the case of the example, that would be the instance of <code>LINKED_LIST [STRING]</code> called <code>my_list</code>. Applying the feature <code>item</code> to <code>my_list</code> retrieves the list element currently referenced by the cursor. In the iteration version of traversal, the variable <code>ic</code> holds the iteration cursor, external to the list object. So, you apply <code>ic.item</code> to get the current list element. The advantage to the external cursor is that multiple traversals of the structure can occur simultaneously without interfering with one another. This is possible in the base form, but only by saving and restoring the structure's cursor.
|
||||
|
||||
|
||||
{{recommended|The ''iteration'' form of the loop construct is not appropriate for use in cases in which the target structure may be changed during the traversal. Therefore, it is recommended that if you choose to alter the structure during traversal, you use the ''base'' loop form with explicit cursor manipulation. This is still tricky business, so you should be certain to protect your work with appropriate contracts.}}
|
||||
|
||||
|
||||
Lastly, of course, the iteration form includes an ''<code>end</code> part'' ... at the end.
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user