bugGNU Octave - Bugs: bug #52292, behavior of "break"...

 
 

bug #52292: behavior of "break" changed and is now incompatible to Matlab

Submitter:  Hartmut <hardy>
Submitted:  Thu 26 Oct 2017 07:45:17 PM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Invalid / Not an Octave Bug Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Fri 27 Oct 2017 05:58:42 PM UTC, comment #4: 

Alright. The behavior of current Matlab (see comment #2) convinces  me, that it's good for Octave to keep its current (dev Octave) behavior. So I'll get used to using "return" instead of "break" in this case.

@Marco: Thanks for testing.

Hartmut <hardy>
Fri 27 Oct 2017 04:48:26 PM UTC, comment #3: 

Looks like Octave is now compatible with current versions of Matlab, so we have increased compatibility with this change. Closing as invalid.

Mike Miller <mtmiller>
Group Member
Fri 27 Oct 2017 08:28:43 AM UTC, comment #2: 

@ Hartmut: if I run your code in R2017b prompt, I get


Error: A BREAK statement appeared outside of a loop. Use RETURN instead.


If I put your code in a script and run it, I get


Error: File: /home/caliari/example.m Line: 2
A BREAK may only be used within a FOR or WHILE loop, and then only within the same file as its corresponding FOR
or WHILE statement.


Marco Caliari <caliari>
Group Member
Thu 26 Oct 2017 08:24:55 PM UTC, comment #1: 

Refer to bug #39168 for the bug report that inspired this change. In that report the user expected that a "break" inside a script that was called from a loop in a different script would break out of the loop.

IMHO you should be using "return" if you want a script to exit early.

Mike Miller <mtmiller>
Group Member
Thu 26 Oct 2017 07:45:17 PM UTC, original submission:  

The following example code can be run as a script file (let's say example.m) in Octave 4.2.1 and in Matlab R2014b without any problem. But in current dev Octave (e.g. with 209e4f34d243) it throws an error.


1+1
break
2+2


The error message in current dev Octave is:


>> example

parse error near line 2 of file example.m

  break must appear in a loop in the same file as loop command

>>> break
        ^


I understand that the content of this error message is correct. I also know that the Matlab help does not encourage this usage of the break command, they say:


break is not defined outside a for or while loop. To exit a function, use return.


Netherless I would like to have this reverted to the previous behavior (i.e. no error message) because:

  • Matlab throws NO error in this case (tested for R2014b, or have they changed this in newer versions?)
  • I am used to using "break" in this way, to conveniently stop a script somewhere in the middle. (I think I've seen others comment on this changed behavior as well.) And I might even like Octave to still support my old habit as an "Octave only" feature, even if Matlab did not support this any more.


What do people think about this? What is a current Matlab version doing in this case? Or should I change my old habit and use "return" from now on?

Hartmut <hardy>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by caliari (Posted a comment)
  • -email is unavailable- added by mtmiller (Posted a comment)
  • -email is unavailable- added by hardy (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2017-10-27 mtmiller StatusNone Invalid / Not an Octave Bug
        Open/ClosedOpen Closed

    Back to the top

    Powered by Savane 3.13-02a9.
    Corresponding source code