|
| From: | Andrew Janke |
| Subject: | [Octave-bug-tracker] [bug #55995] "continue" is dynamically, not lexically scoped - callable from functions without for loops |
| Date: | Mon, 25 Mar 2019 03:43:35 -0400 (EDT) |
| User-agent: | Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.75 Safari/537.36 |
Follow-up Comment #1, bug #55995 (project octave):
Oops. Messed up the formatting and it lost most of my post. Re-post:
In Octave, you can call "continue" from within a function that does not itself
contain a for loop, and it will either cause a continuation in a for loop in a
calling function, or do nothing.
Example:
looper.m:
function looper
for i = 1:5
fprintf ("before\n");
other_fcn ();
fprintf ("after\n");
end
end
other_fcn.m:
function other_fcn
continue
end
Output:
>> looper
before
before
before
before
before
>> continue
>> continue
>> continue
>> other_fcn
>> other_fcn
>>
Note that you can just call continue even if there's no for loop in the
enclosing dynamic scope, and it does nothing.
Is this expected behavior? I saw it discussed over in
https://savannah.gnu.org/bugs/?48665 related to a crash, but not mentioning
that the behavior itself is odd.
Break doesn't behave the same way: it raises an error if you try to call it
outside the lexical scope of a for loop.
call_break.m:
function call_break
break
endfunction
>> break
parse error:
break must appear in a loop in the same file as loop command
>>> break
^
>> call_break
parse error near line 2 of file /Users/janke/tmp/octave-continue/call_break.m
break must appear in a loop in the same file as loop command
>>> break
^
>>
_______________________________________________________
Reply to this item at:
<https://savannah.gnu.org/bugs/?55995>
_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/
| [Prev in Thread] | Current Thread | [Next in Thread] |