help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: strange for .. end syntax or bug?


From: John W. Eaton
Subject: Re: strange for .. end syntax or bug?
Date: Sat, 27 Sep 2008 12:34:58 -0400

On 27-Sep-2008, Carlo de Falco wrote:

| 
| On 27/set/08, at 09:37, Francesco Potorti` wrote:
| 
| > In 3.0.1 I get a case where 'end' and 'endfor' behave differently:
| >
| > octave> for i=1:2 for j=3:4 disp([i j]) end end
| > parse error:
| >
| > syntax error
| >
| >>>> for i=1:2 for j=3:4 disp([i j]) end end
| >                                       ^
| 
| I think this is normal, correct syntax would be
| 
|  >> for i=1:2 for j=3:4 disp([i j]); end; end
|    1   3
|    1   4
|    2   3
|    2   4
| 
| which works fine
| > octave> for i=1:2 for j=3:4 disp([i j]) endfor endfor
| >  1   3
| >  1   4
| >  2   3
| >  2   4
| 
| I'm surprised this works...

The "end" and "endfor" tokens must be handled differently because end
can appear as part of an index expression (i.e., vec(1:end).  The
above may still be a bug, but you can work around it in several ways.
For example, you can write

  for i=1:2 for j=3:4 disp([i j]), end end
  for i=1:2 for j=3:4 disp([i j]), end, end
  for i=1:2 for j=3:4 disp([i j]), end; end

all of which appear to work.  Also, your original statement

  for i=1:2 for j=3:4 disp([i j]) end end

appears to fail in Matlab, so I don't see that trying to fix this (if
it is even possible) has a high priority.

jwe


reply via email to

[Prev in Thread] Current Thread [Next in Thread]