[PN] 2007.10.20 This page is dedicated to Knuth sections 7.2.1.1 and 7.2.1.2 All the routines on this page generate a sequence of objects, so they are all objects of an iterative type. An '''iterate''' type provides for 3 basic functions, '''init''', '''next''' and '''more'''. '''init''' gets things rolling and returns the first value in the sequence. '''next''' gives you the next value in the sequence or an invalid value '''more''' tells you if the last value you just got with '''init''' or '''next''' is a valid value or not. Typically a value of an empty list is the standard invalid value, Because all these routines return a sequence of values which mean something in relation to each other, {} is never a valid returned value. However in some cases {{}},the empty set, may be returned. The '''iterate''' command returns a handle to an interative type of the kind that you have requested in the command. There is a seemingly endless variety of these as this page will demonstrate. The handle is '''it''' followed by a self appointed number, e.g. '''it4''. This handle is an iterative object and is typically invoked in this way: set o [iterate ....] for {set i [$o init]} {[$o more]} {set i [$o next]} { do something with $i } "type delete" $o When you are iterating a number of sequences in the same program this form of expression is easier to use than the namespace version. Because they all have the same init, next and more commands, the commands have to be disambiguated by using the object name all the time. This means that these iterative objects have been implemented in the form of something I call a '''type'''. A type consists of a namespace for the object, plus the 3 commands implemented as procedures: "$o init", "$o next" and "$o more". To avoid having to use quotes everywhere you use the '''type create''' command to make these availbale at a more readable level. The contents of the namespace reamins private. The '''iterate''' command uses '''type create''' inside it as part of creating the iterative object.