Re: evaluation of if statement
- Posted by munchr at mac.com Mar 17, 2002
- 373 views
At 06:10 PM 17/03/2002 -0800, I wrote: >I can't seem to get the following code to work. Should this work like >I expect it to, or does it need to be rewritten? > >Ideally, given a sequence of {1,2,3} it should evaluate false, but >given {'b',2,3}, or {'b','B','b'} it should process true when >"position" corresponds to the position of the letter in the sequence. >But it always processes as false, even when the sequence element >has an ascii value between 'Z' and 'A'. > >for position = 1 to length(input) do > if 'Z' >= upper(input[position]) >= 'A' then > found = find(upper(input[position]), upper(mapping)) > else > found = find(input[position], mapping) > end if >end for I changed the order of the if statement to if 'A' <= upper(input[position]) <= 'Z' then and now it seems to work fine. Any explanation why simply changing the order of 'A' and 'Z' with the corresponding change to the >= evaluations would change the outcome? From what I can tell, the two lines are functionally equivalent and should both work. if 'Z' >= upper(input[position]) >= 'A' then -- won't work if 'Z' is greater than/equal to variable is greater than/equal to 'A' if 'A' <= upper(input[position]) <= 'Z' then -- works if 'A' is less than/equal to variable is less than/equal to 'Z' Am I wrong about this? James Powell Now I'm really confused