Multiple comparison operators in one parentheses Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
pneumatic
Posts: 338
Joined: 05 Dec 2016, 01:51

Multiple comparison operators in one parentheses

11 May 2021, 21:34

AHK v1 accepts this code:

Code: Select all

var := 0
if (0 < var < 100)
	msgbox var is between 0 and 100
else
	msgbox var is NOT between 0 and 100
The (0 < var < 100) is not being evaluated as I was expecting (I've tried adding % and removing brackets).

What does ahk interpret (0 < var < 100) as exactly? I've looked in the manual but couldn't seem to find anything.

Apologies in advance.
User avatar
mikeyww
Posts: 26889
Joined: 09 Sep 2014, 18:38

Re: Multiple comparison operators in one parentheses  Topic is solved

11 May 2021, 21:46

Righto. My guess: 0 < var evaluates to 0. That value < 100 evaluates to 1, so the result is 1.

Another one:

Code: Select all

Send % 1 < 2 < 1
1 < 2 is 1. 1 < 1 is 0, so the result is 0.

You can now guess the next two correctly.

Code: Select all

Send % (1 < 2 < 3) "`n" (1 < (2 < 3))
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Multiple comparison operators in one parentheses

11 May 2021, 22:01

https://www.autohotkey.com/docs/Language.htm#operators
left-to-right based on precedence, unless otherwise specified

as to why it is that way - it would be more difficult to parse correctly if adhering to the mathematical notation

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: doodles333, mikeyww and 303 guests