octave-maintainers
[Top][All Lists]
Advanced

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

Break as valid logical expression


From: John W. Eaton
Subject: Break as valid logical expression
Date: Wed, 13 Nov 2002 10:28:27 -0600

On 13-Nov-2002, Pascal A. Dupuis <address@hidden> wrote:

| On Tue, 12 Nov 2002, John W. Eaton wrote:
| 
| [...]
|
| >   for i = 1:10, i, i == 3 && (x = break); end, x
| >
| > but not
| >
| >   for i = 1:10, i, i == 3 && (x = break + 1); end, x
| >
| > In all cases, the value of break, continue, and return is logical
| > TRUE.
| >
| > Should the use of these new "expressions" be available for use in any
| > kind of expression (addition, subtraction, etc.) or be restricted even
| > more (say, only in && and || expressions?
|
| Hello John,
| 
| thank you for taking into account my remark. As I said, with a Perl
| background, the idea is to make legal such statements as
| some_test() || do_that,
| 
| whith 'do_that' something with can be _evaluated_ .
| So I think it makes sense to have break, continue, and return considered
| as valid "expression" in the context of a "&&" or a "||" operator, but,
| quite frankly, I don't understand what would mean a "x=break" statement.

Neither do I, which is why I was asking whether these expressions
(break, continue, return) should be limited to only && and ||
expressions).

| To be more precise, I would say that break and friends should be
| considered as valid *logical* expression as long as their "return" value
| is not used after the whole statement has been evaluated,

I don't know how to limit that given the current implementation of
Octave's interpreter.  As things are now, break, continue, and return
simply set a global flag which is inspected by the interpreter when
the next expression is evaluated.  In order to be valid in any
expression context (even if limited to && and || expressions), they
must return some value.

jwe



reply via email to

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