BookmarkSubscribe
Choose Language Hide Translation Bar
Jaz
Jaz
Community Trekker

RE: If Statement Evaluates for Both True & False

Hi, 

 

I  was wondering why in the following if statement both parts of the statement are executed when I run the script? It somehow evaluates the statement to both true and false. 

For (k = 1, k <= N Rows(dx), k++,
	Current Data Table (dt); 
	q = k-1;   
	For Each Row(
		If(dt:colAutomatically <= colManuallyEnd[k] & dt:colAutomatically >= colManuallyStart[k], dt:newInstructionsColumn = colInstructions[k], print("No")); 
	); 
);

If true it should execute the following line: 

dt:newInstructionsColumn = colInstructions[k]

If false it should execute the following line: 

print("No")

Any help would be appreciated. 

0 Kudos
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
txnelson
Super User

RE: If Statement Evaluates for Both True & False

Try using this code to check out what is going on

For( k = 1, k <= N Rows( dx ), k++,
	Current Data Table( dt );
	q = k - 1;
	For Each Row(
		If( dt:colAutomatically <= colManuallyEnd[k] & dt:colAutomatically >= colManuallyStart[k],
			dt:newInstructionsColumn = colInstructions[k];
			Print( "\!nYes ", Row(), " ", dt:newInstructionsColumn[Row()] );
		,
			Print( "\!nNo ", Row() )
		)
	);
);
Jim
2 REPLIES 2
Highlighted
txnelson
Super User

RE: If Statement Evaluates for Both True & False

Try using this code to check out what is going on

For( k = 1, k <= N Rows( dx ), k++,
	Current Data Table( dt );
	q = k - 1;
	For Each Row(
		If( dt:colAutomatically <= colManuallyEnd[k] & dt:colAutomatically >= colManuallyStart[k],
			dt:newInstructionsColumn = colInstructions[k];
			Print( "\!nYes ", Row(), " ", dt:newInstructionsColumn[Row()] );
		,
			Print( "\!nNo ", Row() )
		)
	);
);
Jim
pmroz
Super User

RE: If Statement Evaluates for Both True & False

The line that might be causing trouble is this one:

Current Data Table( dt );

If any of your variables are referencing other table columns (like the dx table) I'm not sure what the current data table will actually be.  It's safer to qualify all columns with the table that they're in.  For example where does colManuallyEnd point to?  

colManuallyEnd[k]

I suspect that it's a column in the dx table.  Maybe safer to say

dx:colManuallyEnd[k]

If indeed there's a column called colManuallyEnd.

 

Otherwise put a bunch of print statements inside your loop as Jim suggested.