Page 1 of 1

Nesting Condition in REXX

PostPosted: Fri Apr 10, 2020 11:45 pm
by mahsa
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?

Re: Nesting Condition in REXX

PostPosted: Sat Apr 11, 2020 1:04 am
by prino
Line 42 of your code is the problem!

Re: Nesting Condition in REXX

PostPosted: Sat Apr 11, 2020 1:10 am
by dneufarth
Show the REXX code and error messages. Prino may be correct.

Re: Nesting Condition in REXX

PostPosted: Sat Apr 11, 2020 1:41 am
by willy jensen
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.

Re: Nesting Condition in REXX

PostPosted: Sat Apr 11, 2020 4:47 am
by Pedro
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
 

Re: Nesting Condition in REXX

PostPosted: Sat Apr 11, 2020 11:55 am
by mahsa
thank guys,
It's solved now!

Re: Nesting Condition in REXX

PostPosted: Sun Apr 12, 2020 12:15 am
by sergeyken
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 ‘;’

Re: Nesting Condition in REXX

PostPosted: Tue Apr 14, 2020 6:58 pm
by sergeyken
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

Re: Nesting Condition in REXX

PostPosted: Wed Apr 15, 2020 5:49 am
by Pedro
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

Re: Nesting Condition in REXX

PostPosted: Wed Apr 15, 2020 6:46 pm
by sergeyken
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