octave-bug-tracker
[Top][All Lists]
Advanced

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

[Octave-bug-tracker] [bug #50893] for loop index variable not initialize


From: Rik
Subject: [Octave-bug-tracker] [bug #50893] for loop index variable not initialized unless loop is entered
Date: Sat, 29 Apr 2017 23:42:06 -0400 (EDT)
User-agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:53.0) Gecko/20100101 Firefox/53.0

Follow-up Comment #9, bug #50893 (project octave):

Item 3 seems like a side effect of Matlab's internal implementation and it
doesn't look critical to copy that.

However, I could easily see items #1 and #2 being a problem.

In the first case, code might calculate a collection which is then iterated
over.  If the collection happened to be empty, but with multiple columns, then
Octave would actually execute the loop body.  This would be terribly hard to
debug because most of the time the script would get the same answer in Octave
or Matlab, but occasionally you would get different results based on the
peculiarities of the input data.

It would be slightly harder, but not that much harder, to get the same
behavior from case #2.


for k = COLLECTION
  if (special_condition)
    break;
  end
  ... other code ... 
end  % end for loop

if (k != COLLECTION(end))
  % code to do something when special case was hit
end



If COLLECTION happened to be empty then Octave would not initialize k and the
test on if (k ...) would produce a parse error since the variable is not
defined.  Again, most of the time the script would work but for occasional
data patterns you would get parse errors.

It does seem logical to me that if the expression to iterate over is empty
that you don't execute the loop.  The initialization of the loop variable
seems arbitrary, but we should be able to copy that.



    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?50893>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

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