Problem in getting length



IBM's Command List programming language & Restructured Extended Executor

Problem in getting length

Postby utpalpal07 » Wed Feb 08, 2012 3:28 pm

Hi,
Please review the code below.

/* REXX */                                                             
FOUR_LETTER_WORDS = ''    /* INITIALIZE TO NO 4 LETTER WORDS FOUND YET*/
SAY "ENTER A WORD: "                   /* PROMPT USER TO ENTER 1 WORD */
PARSE PULL WORDIN .       /* THE PERIOD ENSURES ONLY 1 WORD IS READ IN */
SAY LENGTH(WORDIN)                                                     
DO WHILE WORDIN ^= ''                                                   
    IF LENGTH(WORDIN)=4 THEN                                           
    FOUR_LETTER_WORDS = FOUR_LETTER_WORDS WORDIN                       
    SAY "ENTER A WORD: "                     /* READ THE NEXT WORD IN */
    SAY FOUR_LETTER_WORDS                                               
    PARSE PULL WORDIN .                                                 
    SAY LENGTH(WORDIN)                                                 
END                                                                     
SAY 'FOUR LETTER WORDS:' FOUR_LETTER_WORDS                             


here is the output:
ENTER A WORD:
have
6
***
ENTER A WORD:

have
4
ENTER A WORD:
have
nice
4
ENTER A WORD:
have nice
day
3
ENTER A WORD:
have nice

0
FOUR LETTER WORDS: have nice




I want to ask that why 1st "have" showing length=6 while 2nd "have" showing length=4 only. and so 1st "have" is not being considered. Why is it so?
utpalpal07
 
Posts: 43
Joined: Wed Feb 08, 2012 12:02 pm
Has thanked: 1 time
Been thanked: 0 time

Re: Problem in getting length

Postby Akatsukami » Wed Feb 08, 2012 4:07 pm

You realize that space is a character, yes?
"You have sat too long for any good you have been doing lately ... Depart, I say; and let us have done with you. In the name of God, go!" -- what I say to a junior programmer at least once a day
User avatar
Akatsukami
Global moderator
 
Posts: 1058
Joined: Sat Oct 16, 2010 2:31 am
Location: Bloomington, IL
Has thanked: 6 times
Been thanked: 51 times

Re: Problem in getting length

Postby mongan » Wed Feb 08, 2012 6:30 pm

Not to say that the way you built your logic makes your entries and text confusing to read. At first glance it looks like the value of your four letter word variable is the input to your enter a word request, and only looking at the code makes it clear what is going on. Usability and clarity are very important.
User avatar
mongan
 
Posts: 211
Joined: Tue Jan 11, 2011 8:32 pm
Has thanked: 1 time
Been thanked: 5 times

Re: Problem in getting length

Postby utpalpal07 » Thu Feb 09, 2012 3:04 pm

Thanks for ur suggestions. got the answer.

it was actually due to the dot in 4th line.
utpalpal07
 
Posts: 43
Joined: Wed Feb 08, 2012 12:02 pm
Has thanked: 1 time
Been thanked: 0 time

Re: Problem in getting length

Postby mongan » Thu Feb 09, 2012 9:28 pm

Do you understand what the dot does? You probably need to use a strip(wordin,'B') in case you enter spaces behind oder before the word.
User avatar
mongan
 
Posts: 211
Joined: Tue Jan 11, 2011 8:32 pm
Has thanked: 1 time
Been thanked: 5 times


Return to CLIST & REXX

 


  • Related topics
    Replies
    Views
    Last post