Re: Why doesn't foreach return a value



On Jan 30, 9:04 pm, Darren New <d...@xxxxxxxxxx> wrote:
tom.rmadilo wrote:
Call 'return' inside a loop and you will discover the difference
between a function/proc and a foreach loop. Foreach doesn't 'go away',
because the foreach body is executed in the current context.

I have no idea what you think "go away" means there. I know the
difference between a proc and foreach. Call [break] inside a proc and
the proc doesn't "go away" either. Call [error] and both the proc and
the foreach it's in "go away".

You make a good point here. The boundaries of loops and stack levels/
procs are not the same. Where exactly code will resume execution when
interrupted by [break], [continue], [return] or [error] depends on
more than just the command.

By "go away", I only mean that the current context "calls" a command.
A typical proc body isn't executed in the context in which it is
called, it "goes away", and then "returns".
.



Relevant Pages

  • Re: Again: error in event handler while using BLT bgexec: global variable seems to vanish.
    ... will continue to be processed while bgexec is executing. ... execution should be #0 (the toplevel context), but in fact it appears to be ... out) to examine the context of execution. ... foreach you $people { ...
    (comp.lang.tcl)
  • tcsh foreach terminates early & at random.
    ... I've tried to make use of a dual core machine by running a few jobs ... I added 'set verbose' before the foreach and found that the last line of the ... shell script to be executed is usually the "endif" (followed by the ... execution of the command where it gets put into the background. ...
    (comp.unix.shell)
  • Re: Deferred execution versus immediate execution--whats the difference?
    ... are "deferred execution" while other queries are "immediate ... foreach (int i in query) { ... Computing Square... ... not executed until the foreach is executed. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: LINQ and XML for compact framework
    ... Hang on - you said before that it wasn't getting inside the foreach ... You said that "msgs" was empty - which means it wouldn't be ... After it executed that, or during the execution? ... see whether it really does have a MessageStaus element. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: LINQ and XML for compact framework
    ... Hang on - you said before that it wasn't getting inside the foreach ... You said that "msgs" was empty - which means it wouldn't be ... After it executed that, or during the execution? ... see whether it really does have a MessageStaus element. ...
    (microsoft.public.dotnet.languages.csharp)