Re: Why doesn't foreach return a value
- From: Mark Janssen <mpc.janssen@xxxxxxxxx>
- Date: Wed, 30 Jan 2008 07:19:58 -0800 (PST)
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
.
- Follow-Ups:
- Re: Why doesn't foreach return a value
- From: tom.rmadilo
- Re: Why doesn't foreach return a value
- References:
- Re: Why doesn't foreach return a value
- From: Rufus V. Smith
- Re: Why doesn't foreach return a value
- Prev by Date: Re: Vista theme for Ttk?
- Next by Date: Re: Package unloading
- Previous by thread: Re: Why doesn't foreach return a value
- Next by thread: Re: Why doesn't foreach return a value
- Index(es):