Nesting Condition in REXX



IBM's Command List programming language & Restructured Extended Executor

Nesting Condition in REXX

Postby mahsa » Fri Apr 10, 2020 11:45 pm

Hi,
I write nesting IF/THEN/ELSE alright but when I try SELECT/WHEN/OTHERWISE/END, I can't make it work. I am writing a SELECT/WHEN/OTHERWISE/END and in one of the WHEN clauses, I am including another SELECT condition. it works all good but I get an error regarding the last OTHERWISE. my last lines are like this:
OTHERWISE SAY 'YOU SHOULD ANSWER WITH A NUMBER' END
OTHERWISE SAY 'You should answer with yes or no' END
each OTHERWISE has a former SELECT in the code.
The first one is for nested one, and the second one is for the big condition.
it gives the error :
IRX0009I Error running CONSE2, line 59: Unexpected WHEN or OTHERWISE
Do You know what should I do?
How should I write nested SELECT/WHEN/OTHERWISE/END?
mahsa
 
Posts: 2
Joined: Fri Apr 10, 2020 11:11 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Nesting Condition in REXX

Postby prino » Sat Apr 11, 2020 1:04 am

Line 42 of your code is the problem!
Robert AH Prins
robert.ah.prins @ the.17+Gb.Google thingy
User avatar
prino
 
Posts: 641
Joined: Wed Mar 11, 2009 12:22 am
Location: Vilnius, Lithuania
Has thanked: 3 times
Been thanked: 29 times

Re: Nesting Condition in REXX

Postby dneufarth » Sat Apr 11, 2020 1:10 am

Show the REXX code and error messages. Prino may be correct.
dneufarth
 
Posts: 23
Joined: Thu Oct 15, 2009 2:50 am
Has thanked: 1 time
Been thanked: 2 times

Re: Nesting Condition in REXX

Postby willy jensen » Sat Apr 11, 2020 1:41 am

if this really is what you code, then there is your error:
OTHERWISE SAY 'YOU SHOULD ANSWER WITH A NUMBER' END

it must be either (note the semicolon)
OTHERWISE SAY 'YOU SHOULD ANSWER WITH A NUMBER'; END
or (preferred method)
OTHERWISE SAY 'YOU SHOULD ANSWER WITH A NUMBER'
END

END must be a seperate statement.
willy jensen
 
Posts: 465
Joined: Thu Mar 10, 2016 5:03 pm
Has thanked: 0 time
Been thanked: 70 times

Re: Nesting Condition in REXX

Postby Pedro » Sat Apr 11, 2020 4:47 am

OTHERWISE SAY 'YOU SHOULD ANSWER WITH A NUMBER' END
OTHERWISE SAY 'You should answer with yes or no' END


I am not sure what the 'END' here is... If that is the END to the SELECT, you should separate two statements that are on the same line with a semicolon.

For clarity, I would enclose any nested stuff between a Do and End:

Select
  When ( blah) Then
     Do;
       (blah)
     End;
  Otherwise
     Do;
      (blah)
   End;
End;
 


In the ISPF editor, you can turn on the context sensitive highlighting to match the start & end keywords. Specify these commands:
HI ON
HI PAREN
HI LOGIC
 
Pedro Vera
User avatar
Pedro
 
Posts: 686
Joined: Thu Jul 31, 2008 9:59 pm
Location: Silicon Valley
Has thanked: 0 time
Been thanked: 53 times

Re: Nesting Condition in REXX

Postby mahsa » Sat Apr 11, 2020 11:55 am

thank guys,
It's solved now!
mahsa
 
Posts: 2
Joined: Fri Apr 10, 2020 11:11 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Nesting Condition in REXX

Postby sergeyken » Sun Apr 12, 2020 12:15 am

mahsa wrote:Do You know what should I do?
How should I write nested SELECT/WHEN/OTHERWISE/END?


1. You must RTFM

2. END terminates the corresponding SELECT, not previous OTHERWISE

3. END when coded in the same line with previous statements must be separated by semicolon ‘;’
Javas and Pythons come and go, but JCL and SORT stay forever.
User avatar
sergeyken
 
Posts: 437
Joined: Wed Jul 24, 2019 10:12 pm
Has thanked: 7 times
Been thanked: 40 times

Re: Nesting Condition in REXX

Postby sergeyken » Tue Apr 14, 2020 6:58 pm

Pedro wrote:
OTHERWISE SAY 'You should answer with yes or no' END


I am not sure what the 'END' here is...

In this case END is an undefined REXX variable. By default it is assigned its own name in caps: END = 'END'

So, the whole statement is converted sequentially
SAY 'You should answer with yes or no' END
SAY 'You should answer with yes or no' 'END'
SAY 'You should answer with yes or no END'
If it was executed successfully, it would result in the output:
You should answer with yes or no END
Javas and Pythons come and go, but JCL and SORT stay forever.
User avatar
sergeyken
 
Posts: 437
Joined: Wed Jul 24, 2019 10:12 pm
Has thanked: 7 times
Been thanked: 40 times

Re: Nesting Condition in REXX

Postby Pedro » Wed Apr 15, 2020 5:49 am

I think the main problem could have easily been resolved while writing the program.

In the ISPF editor, you can turn on the context sensitive highlighting to match the start & end keywords. Specify these commands:
HI ON
HI PAREN
HI LOGIC
 

Through the use of different colors in the editor, it will become clear which End is matched to which DO or which SELECT
Pedro Vera
User avatar
Pedro
 
Posts: 686
Joined: Thu Jul 31, 2008 9:59 pm
Location: Silicon Valley
Has thanked: 0 time
Been thanked: 53 times

Re: Nesting Condition in REXX

Postby sergeyken » Wed Apr 15, 2020 6:46 pm

Pedro wrote:I think the main problem could have easily been resolved while writing the program.

In the ISPF editor, you can turn on the context sensitive highlighting to match the start & end keywords. Specify these commands:
HI ON
HI PAREN
HI LOGIC
 

Through the use of different colors in the editor, it will become clear which End is matched to which DO or which SELECT

Or, you can enter command HI{LITE} without parameters, to get the whole panel with multiple HILIGHT options:
  File  Languages  Colors  Help                                            
                            Edit Color Settings                            
  Command ===>                                                              
                                                                 More:     +
  Language:  1   1. Automatic      Coloring: 3  1. Do not color program      
                 2. Assembler                   2. Color program            
                 3. BookMaster                  3. Both IF and DO logic      
                 4. C                           4. DO logic only            
                 5. COBOL                       5. IF logic only            
                 6. HTML                                                    
                 7. IDL            Enter "/" to select option                
                 8. ISPF DTL       /  Parentheses matching                  
                 9. ISPF Panel     /  Highlight FIND strings                
                10. ISPF Skeleton  /  Highlight cursor phrase                
                11. JCL                                                      
                12. Pascal         Note: Information from this panel is      
                13. PL/I           saved in the edit profile.                
                14. REXX                  
                15. SuperC                
                16. XML                  
                17. Other                
                18. Default              
   F1=Help        F2=Split       F3=Exit        F7=Backward    F8=Forward    
   F9=Swap       F10=Actions    F12=Cancel                                  
 
Javas and Pythons come and go, but JCL and SORT stay forever.
User avatar
sergeyken
 
Posts: 437
Joined: Wed Jul 24, 2019 10:12 pm
Has thanked: 7 times
Been thanked: 40 times


Return to CLIST & REXX

 


  • Related topics
    Replies
    Views
    Last post