On 17/06/2013 11:08, paskali wrote:
> I am from C where foreach there is not.
> However, i think, it is a issue of habit.
> Of course there is the case in which a solution is better then an other.
If you're wanting to go over the elements of a list *without* changing
them, [foreach] is wonderful. If you're adding, removing or changing
elements as you go and you want to see those modifications (really
useful in some algorithms!) then you need to use the more primitive
[for] or [while].
Also, don't forget that there's also [dict for] for going over
dictionaries (and [lmap] and [dict map] for remapping in 8.6). These are
all things not found in C; Tcl isn't C. :-)
Donal.
--
Donal Fellows — Tcl user, Tcl maintainer, TIP editor.