Re: Why doesn't foreach return a value



On 28 jan, 21:10, "Rufus V. Smith" <nos...@xxxxxxxxxx> wrote:
You are attempting to return a non-initialized variable as
the body of the foreach command never is executed.

I'm not a tcl expert, but what would this return, may I ask:

proc test {l} {
   set itemcount 0
   foreach a $l {incr itemcount}
   return $itemcount

}

An empty list should return zero itemcount, it would return
one in your scheme, wouldn't it?

As would a single-element list.

(never mind that you should use llength $l )

Rufus


No this would not return 1, the body never gets executed if $l eq {}
so $itemcount will still be 0. The result of the [foreach a $l {incr
itemcount}] would be {} though (as it is now)

Mark
.