Page 1 of 1

why and operator is not working

PostPosted: Wed Sep 28, 2016 11:47 am
by arya_starc
Hi All,

I gave this AND operator in REXX but it is not working in that way

/* REXX                            */                                                                00010000
DO WHILE (DATATYPE(LAST) \= 'NUM' & LENGTH(LAST) \=2)                   00020014
   SAY 'LENGTH OF LAST IS 'LENGTH(LAST)                                            00030009
   SAY 'PLEASE ENTER THE LUNCH AMOUNT AGAIN'                                00031009
   SAY 'THE AMOUNT YOU ENTERED WAS NOT A NUMBER WITHOUT A DOLLAR SIGN'  00040000
   PARSE PULL LAST                                                                             00050000
END                                                                                                   00060000
 


it go inside loop only both condition is satisfied..
but it's not happening
!!

Re: why and operator is not working

PostPosted: Wed Sep 28, 2016 11:50 am
by enrico-sorichetti
NUMBER OFF ?

Re: why and operator is not working

PostPosted: Wed Sep 28, 2016 12:18 pm
by prino
Paste ALL code, and not just some cut-out stuff!

Re: why and operator is not working

PostPosted: Wed Sep 28, 2016 12:52 pm
by willy jensen
The logic is wrong, try with OR instad:
DO WHILE (DATATYPE(LAST) \= 'NUM' | LENGTH(LAST) \=2)

Re: why and operator is not working

PostPosted: Wed Sep 28, 2016 3:45 pm
by NicC
Unless you 'Pull' LAST before your Do While LAST will have the value 'LAST'.

Why did you not run a trace before posting - you would have seen this at that point.

And as an efficiency point - why calculate the length of LAST more than once?

Re: why and operator is not working

PostPosted: Wed Sep 28, 2016 4:49 pm
by willy jensen
NicC has a valid point, you should initialize variables before using DO WHILE. In this particular it doesn't matter as the DO WHILE is at the start of the program so all variables have their default values (their name in uppercase).
I would turn the thing around and do
DO UNTIL DATATYPE(LAST) = 'NUM' & LENGTH(LAST) =2

then you don't need to worry about variable contents before the loop. And I find it cleaner too testing for EQ instead of NE.

Re: why and operator is not working

PostPosted: Wed Sep 28, 2016 5:56 pm
by enrico-sorichetti
IMO
in any well behaved REXX script ALL the variables should be initialised
and an ON VALUE clause be specified


#! /usr/bin/env rexx

Trace "O"
signal on novalue name novalue

exit

/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*/
novalue:
say  "** "copies("- ",35)
say  "** Novalue trapped, at line("sigl") var('"condition("D")"') "
exit
 


for TSO change the first line to
"/* REXX */