cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
AT
AT
Level V

Skip below lines if a table is empty inside a for loop

 Hi, I have the following script which is inside a for loop. I like to continue the loop if table mydt is empty and skip lines below it. 

 

I appreciate your help. Thanks

-------------------------------------------

mydt = Data Table( dt5 );

 

    if((is empty(mydt)), continue());

    

mydtsummary = Data Table( dt5 ) << Summary(

 

Group( :BoardNo ),

 

Max( :starttime ),

 

statistics column name format( "stat of column" )

 

);

 

mydt << Update(

 

With( Data Table( mydtsummary ) ),

 

Match Columns( :BoardNo = :BoardNo ),

 

Add Columns from Update table( :Max of starttime )

 

);

 

mydt << select where( :starttime == :Max of starttime ) << invert row selection;

 

mydt << delete rows;

 

mydt << delete columns( "Max of starttime" );

 

Close( mydtsummary, nosave );

Close(mydt,save);

6 REPLIES 6
cwillden
Super User (Alumni)

Re: Skip below lines if a table is empty inside a for loop

Why not just reverse the logic using "!" and stick all those lines in your if statement?

If( !Is Empty( mydt ),
	mydtsummary = Data Table( dt5 ) << Summary(
		Group( :BoardNo ),
		Max( :starttime ),
		statistics column name format( "stat of column" )
	);

	mydt << Update(
		With( Data Table( mydtsummary ) ),
		Match Columns( :BoardNo = :BoardNo ),
		Add Columns from Update table( :Max of starttime )
	);

	mydt << select where( :starttime == :Max of starttime ) << invert row selection;

	mydt << delete rows;

	mydt << delete columns( "Max of starttime" );

	Close( mydtsummary, nosave );
	Close( mydt, save );
);
-- Cameron Willden
AT
AT
Level V

Re: Skip below lines if a table is empty inside a for loop

Thanks for quick feedback and solution. I tried it but I get an error in the update section.

 

missing argument{8} in access or evaluation of 'Data Table' , Data Table/*###*/(mydtsummary)

mydt << Update(

With( Data Table/*###*/(mydtsummary) ),

 

Looks like it is processing Update section when mydt is empty and it should not. Thanks

cwillden
Super User (Alumni)

Re: Skip below lines if a table is empty inside a for loop

What are you using the Is Empty() function to do?  If it is to check if the table itself has no data in it, you are using this function incorrectly.  It will tell you if the variable mydt (not the data table it references) has no value or has the empty value.  If you want to check if the data table has nothing in it, then do something like N Row(mydt) == 0 as your logical check.

-- Cameron Willden
AT
AT
Level V

Re: Skip below lines if a table is empty inside a for loop

Thanks Cameron. The issue is not whether the table is empty or has no value. the issue, if the condition is true, I want to skip all the lines below that and go to the next for loop index.

 

if (condition = True,

 ....

 ...    skip all below

 ...

);

 

Thanks.

 

 

txnelson
Super User

Re: Skip below lines if a table is empty inside a for loop

If( condition == true,

     Break();

);

Jim
AT
AT
Level V

Re: Skip below lines if a table is empty inside a for loop

Thanks Jim.