why and operator is not working



IBM's Command List programming language & Restructured Extended Executor

why and operator is not working

Postby arya_starc » Wed Sep 28, 2016 11:47 am

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
!!
arya_starc
 
Posts: 136
Joined: Mon Sep 21, 2015 1:39 pm
Has thanked: 5 times
Been thanked: 0 time

Re: why and operator is not working

Postby enrico-sorichetti » Wed Sep 28, 2016 11:50 am

NUMBER OFF ?
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 2994
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 164 times

Re: why and operator is not working

Postby prino » Wed Sep 28, 2016 12:18 pm

Paste ALL code, and not just some cut-out stuff!
Robert AH Prins
robert.ah.prins @ the.17+Gb.Google thingy
User avatar
prino
 
Posts: 635
Joined: Wed Mar 11, 2009 12:22 am
Location: Vilnius, Lithuania
Has thanked: 3 times
Been thanked: 28 times

Re: why and operator is not working

Postby willy jensen » Wed Sep 28, 2016 12:52 pm

The logic is wrong, try with OR instad:
DO WHILE (DATATYPE(LAST) \= 'NUM' | LENGTH(LAST) \=2)
willy jensen
 
Posts: 455
Joined: Thu Mar 10, 2016 5:03 pm
Has thanked: 0 time
Been thanked: 69 times

Re: why and operator is not working

Postby NicC » Wed Sep 28, 2016 3:45 pm

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?
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 3025
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisies (almost)
Has thanked: 4 times
Been thanked: 136 times

Re: why and operator is not working

Postby willy jensen » Wed Sep 28, 2016 4:49 pm

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.
willy jensen
 
Posts: 455
Joined: Thu Mar 10, 2016 5:03 pm
Has thanked: 0 time
Been thanked: 69 times

Re: why and operator is not working

Postby enrico-sorichetti » Wed Sep 28, 2016 5:56 pm

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 */
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 2994
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 164 times


Return to CLIST & REXX

 


  • Related topics
    Replies
    Views
    Last post