Page 1 of 1

Problem in getting length

PostPosted: Wed Feb 08, 2012 3:28 pm
by utpalpal07
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?

Re: Problem in getting length

PostPosted: Wed Feb 08, 2012 4:07 pm
by Akatsukami
You realize that space is a character, yes?

Re: Problem in getting length

PostPosted: Wed Feb 08, 2012 6:30 pm
by mongan
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.

Re: Problem in getting length

PostPosted: Thu Feb 09, 2012 3:04 pm
by utpalpal07
Thanks for ur suggestions. got the answer.

it was actually due to the dot in 4th line.

Re: Problem in getting length

PostPosted: Thu Feb 09, 2012 9:28 pm
by mongan
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.