turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- JMP User Community
- :
- Discussions
- :
- Discussions
- :
- RE: If Statement Evaluates for Both True & False

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Jun 14, 2018 7:13 AM
(228 views)

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.

Solved! Go to Solution.

- Tags:
- boolean
- if
- ifstatement

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Jun 14, 2018 8:12 AM
(358 views)

Solution

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Jun 14, 2018 8:12 AM
(359 views)

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Jun 14, 2018 10:08 AM
(191 views)

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.