Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Evaluation Order in a Condition statement

Reply
Thread Tools

Evaluation Order in a Condition statement

 
 
David Côme
Guest
Posts: n/a
 
      03-18-2008
Hello.

Let A and B be 2 boolean expressions.
In the instruction if(A && B){/*..*/}, does the standard certify that A
will be evaluated first ?

Thanks a lot.
 
Reply With Quote
 
 
 
 
Christopher
Guest
Posts: n/a
 
      03-18-2008
On Mar 18, 3:32 pm, David Côme <davidc...@wanadoo.fr> wrote:
> Hello.
>
> Let A and B be 2 boolean expressions.
> In the instruction if(A && B){/*..*/}, does the standard certify that A
> will be evaluated first ?
>
> Thanks a lot.


left to right
 
Reply With Quote
 
 
 
 
Paavo Helde
Guest
Posts: n/a
 
      03-18-2008
=?utf-8?Q?David_C=C3=B4me?= <> wrote in
newsp.t78bb5kyrttu86@debian:

> Hello.
>
> Let A and B be 2 boolean expressions.
> In the instruction if(A && B){/*..*/}, does the standard certify that A
> will be evaluated first ?


Even more: if A yields false, B is not evaluated at all.
 
Reply With Quote
 
red floyd
Guest
Posts: n/a
 
      03-18-2008
David Côme wrote:
> Hello.
>
> Let A and B be 2 boolean expressions.
> In the instruction if(A && B){/*..*/}, does the standard certify that A
> will be evaluated first ?
>


I believe it depends upon whether operator&& is user-defined.
For built-in &&, yes, A is evaluated first, and B will not be evaluated
at all, if A is true.

For user defined &&, I believe the order is unspecified, and that both A
and B will be evaluated.
 
Reply With Quote
 
Alexander Dong Back Kim
Guest
Posts: n/a
 
      03-19-2008
On Mar 19, 7:40 am, Christopher <cp...@austin.rr.com> wrote:
> On Mar 18, 3:32 pm, David Côme <davidc...@wanadoo.fr> wrote:
>
> > Hello.

>
> > Let A and B be 2 boolean expressions.
> > In the instruction if(A && B){/*..*/}, does the standard certify that A
> > will be evaluated first ?

>
> > Thanks a lot.

>
> left to right


This is absolutely right! Lazy evaluation!

Cheers,
 
Reply With Quote
 
Erik Wikström
Guest
Posts: n/a
 
      03-19-2008
On 2008-03-19 05:40, Alexander Dong Back Kim wrote:
> On Mar 19, 7:40 am, Christopher <cp...@austin.rr.com> wrote:
>> On Mar 18, 3:32 pm, David Côme <davidc...@wanadoo.fr> wrote:
>>
>> > Hello.

>>
>> > Let A and B be 2 boolean expressions.
>> > In the instruction if(A && B){/*..*/}, does the standard certify that A
>> > will be evaluated first ?

>>
>> > Thanks a lot.

>>
>> left to right

>
> This is absolutely right! Lazy evaluation!


Short circuit evaluation, lazy evaluation is something else.

--
Erik Wikström
 
Reply With Quote
 
Victor Bazarov
Guest
Posts: n/a
 
      03-19-2008
Erik Wikström wrote:
> On 2008-03-19 05:40, Alexander Dong Back Kim wrote:
>> On Mar 19, 7:40 am, Christopher <cp...@austin.rr.com> wrote:
>>> On Mar 18, 3:32 pm, David Côme <davidc...@wanadoo.fr> wrote:
>>>
>>>> Hello.
>>>
>>>> Let A and B be 2 boolean expressions.
>>>> In the instruction if(A && B){/*..*/}, does the standard certify
>>>> that A will be evaluated first ?
>>>
>>>> Thanks a lot.
>>>
>>> left to right

>>
>> This is absolutely right! Lazy evaluation!

>
> Short circuit evaluation, lazy evaluation is something else.


And actually in 'A && B' the expression 'B' is *not* evaluated at all
if 'A' yields 'false'.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Evaluation order in if statement Bogdan C++ 4 11-26-2011 05:00 PM
Help with while condition OR condition Bill W. Ruby 13 05-09-2011 09:42 PM
Evaluation order of assignment statement nachch@gmail.com C Programming 10 10-24-2006 12:16 AM
Condition outside loop or separate loop for different condition? - Java 12 06-15-2005 08:50 AM
For loop condition evaluation Shill C Programming 6 08-05-2003 12:18 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57