Page 1 of 1

exit from a multiple loop DO

PostPosted: Wed Oct 06, 2021 1:04 pm
by samb01
Hello, i would like to exit the first do if PLATEAU = A, or if PLATEAU = B
The first DO is in the line


 DO J = 1 TO DS2.0  
 


If i use the commande EXIT, i would exit from the DO just before but not the first DO (i don't know if i make me anderstood...)


     "EXECIO * DISKR IN2 (FINIS STEM DS2."                
        DO J = 1 TO DS2.0                                
          IND01 = INDEX(DS2.J,'SCF0350I')                
          IF IND01 <> 0 THEN                              
          DO                                              
            IND02 = INDEX(DS2.J,'401-')                  
            IF IND02 <> 0 THEN                            
              DO                                          
                 PLATEAU = A                              
              END                                        
            ELSE                                          
              DO                                          
                 PLATEAU = B                              
              END                                        
          END                                            
        END                                              
"EXECIO * DISKR IN (FINIS STEM DS."                      
  DO I = 1 TO DS.0                                        
 


Thank's for your help.

Re: exit from a multiple loop DO

PostPosted: Wed Oct 06, 2021 1:11 pm
by willy jensen
Use LEAVE to exit the current DO, EXIT exits the program.

Re: exit from a multiple loop DO

PostPosted: Wed Oct 06, 2021 2:52 pm
by samb01
Hello,

it's not the current do but the do before and before. I you have a look thre are 3 do.
If i lsten to you i would do that :


"EXECIO * DISKR IN2 (FINIS STEM DS2."                
        DO J = 1 TO DS2.0                                
          IND01 = INDEX(DS2.J,'SCF0350I')                
          IF IND01 <> 0 THEN                              
          DO                                              
            IND02 = INDEX(DS2.J,'401-')                  
            IF IND02 <> 0 THEN                            
              DO                                          
                 PLATEAU = A    
                   LEAVE    
              END                                        
            ELSE                                          
              DO                                          
                 PLATEAU = B  
                   LEAVE                          
              END                                        
          END                                            
        END                                              
"EXECIO * DISKR IN (FINIS STEM DS."                      
  DO I = 1 TO DS.0                                        
 

 


but i will get out of this DO :


           DO                                          
                 PLATEAU = B  
                   LEAVE                          
              END              
 


But i want to leave this DO


  DO J = 1 TO DS2.0                                
 

Re: exit from a multiple loop DO

PostPosted: Wed Oct 06, 2021 5:43 pm
by willy jensen
Ok, since J is the controlling variable for that outer loop, you can use LEAVE J.

Re: exit from a multiple loop DO

PostPosted: Wed Oct 06, 2021 10:14 pm
by Pedro
re: " LEAVE J"

Wow! I am excited because I did not know you could do that.

Re: exit from a multiple loop DO

PostPosted: Wed Oct 06, 2021 10:21 pm
by willy jensen
you can also do ITERATE J.
it's all in the manual ;)

Re: exit from a multiple loop DO

PostPosted: Wed Oct 06, 2021 11:01 pm
by sergeyken
I would improve the clarity of the code.
The habit to do so may simplify your life significantly in the future.

"EXECIO * DISKR IN2 (FINIS STEM DS2."                
Do J = 1 To DS2.0                                
   IND01 = Pos( 'SCF0350I', DS2.J )                
   If IND01 <> 0 Then Do                            
      IND02 = Pos( '401-', DS2.J )                  
      If IND02 <> 0 Then                            
         PLATEAU = A    
      Else                                          
         PLATEAU = B  
      Leave J                          
   End /* IND01 */
End J


Another option

"EXECIO * DISKR IN2 (FINIS STEM DS2."                
Do J = 1 To DS2.0                                
   IND01 = Pos( 'SCF0350I', DS2.J )                
   If IND01 = 0 Then
      Iterate J                /* next line now */                          
   IND02 = Pos( '401-', DS2.J )                  
   If IND02 <> 0 Then                            
      PLATEAU = A    
   Else                                          
      PLATEAU = B  
   Leave J                 /* all found, exit loop */
End J

Re: exit from a multiple loop DO

PostPosted: Mon Oct 11, 2021 6:07 pm
by samb01
Hello Sergeyken and thank's for your help.
I like this code because it dosen't have to end the code if the word SCF0350I dosen't exist.


"EXECIO * DISKR IN2 (FINIS STEM DS2."                
Do J = 1 To DS2.0                                
   IND01 = Pos( 'SCF0350I', DS2.J )                
   If IND01 = 0 Then
      Iterate J                /* next line now */                          
   IND02 = Pos( '401-', DS2.J )                  
   If IND02 <> 0 Then                            
      PLATEAU = A    
   Else                                          
      PLATEAU = B  
   Leave J                 /* all found, exit loop */
End J
 

Re: exit from a multiple loop DO

PostPosted: Thu Oct 14, 2021 3:52 am
by Pedro
Can you provide a sample input file?

Re: exit from a multiple loop DO

PostPosted: Thu Oct 14, 2021 1:29 pm
by samb01
Hello :


 CPU1      2021286  09:57:34.62             ISF031I CONSOLE OPC ACTIVATED
 CPU1      2021286  09:57:34.62            -F EMCSCF,DEV,DIS,VOL(CSYS01)
 CPU1      2021286  09:57:34.63             SCF0350I  C103(CSYS01) ONLINE     EMC-000297000402-C100-0000A7-01-03
 CPU1      2021286  09:57:34.63             SCF0356I DEVICE DISPLAY VOLUME COMMAND COMPLETED.