Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / "and" in an "if" behaviour

Author
Message
Riusz
8
Years of Service
User Offline
Joined: 27th Feb 2016
Location:
Posted: 20th Oct 2016 20:45
Hello Everyone,

When I compare AppGameKit Tier 1 with other langages like c, c++, c#, java... when we have many conditions with an "and" operator, the conditions are evaluate in order and if one condition is false the other ones are not evaluated but not in AppGameKit Tier 1.
All conditions are evaluated with "and" even if the first is false :



if I want this kind of condition, I need two ifs :



Do you think this behaviour is wanted or it's a issue ?

Thanks
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 20th Oct 2016 22:12
The functionality you are referring to is "&&", or "AndAlso".
We don't have that in Tier 1, we only have the equivalent of "&" or "And". You have to use your second method.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 20th Oct 2016 23:00
The fact that it ALWAYS resolves all conditions in an if statement is unique to basic and defined as part of the basic language
Riusz
8
Years of Service
User Offline
Joined: 27th Feb 2016
Location:
Posted: 21st Oct 2016 04:51
Thanks you for your answers !!!
Now I know it's normal.
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 21st Oct 2016 08:25
Quote: "The fact that it ALWAYS resolves all conditions in an if statement is unique to basic and defined as part of the basic language"


It is also available in other languages (e.g C#), but it is rarely used. In most usage cases you will see &&, but & is also valid and checks all conditions. If you have a scenario where you can predict that both statements are generally true, you should use &, which is faster.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Scary Little Rabbit
14
Years of Service
User Offline
Joined: 4th Aug 2009
Location: Chelyabinsk, Russian Federation.
Posted: 21st Oct 2016 11:03
BatVink wrote: "The functionality you are referring to is "&&", or "AndAlso"."

also it's known as short-circuit evaluation. I'd like to see this implemented in AGK.
error #1:
'too many stars, too many stares. disembody.'
Unicode yours
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 22nd Oct 2016 03:09
Isn't & the binary "and" operator
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 23rd Oct 2016 10:37
Yes, but it also works as a non-short-circuited test.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
nz0
AGK Developer
16
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 24th Oct 2016 22:32 Edited at: 24th Oct 2016 22:34
I haven't tried it, but shouldn't the parenthesis be prioritised to evaluate?



[edit] oh sorry. Noticed it's about the short circuiting..

Login to post a reply

Server time is: 2024-04-26 05:11:57
Your offset time is: 2024-04-26 05:11:57