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
- :
- RE: If Statement Evaluates for Both True & False

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

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Jun 14, 2018 7:13 AM
(3665 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.

- Tags:
- boolean
- if
- ifstatement

1 ACCEPTED SOLUTION

Accepted Solutions

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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.

Article Labels

There are no labels assigned to this post.