Subscribe Bookmark RSS Feed

If loop question

Hi Guys,

I am trying to use an if loop as below:

3 REPLIES
mpb

Super User

Joined:

Jun 23, 2011

When my code "does not work" I try something simpler to see if I can see what is going on. In this case I'm pretty sure the answer to your "if" question is in the scripting docs. But you can test it for your self by trying simple code such as this:

pmroz

Super User

Joined:

Jun 23, 2011

Three things:

1. Yes the comma is used to separate out the else clause.

2. Your code does not have a matching close parenthese for if(

3. I would not use the letter "j" as a variable, because j is a JSL function. It's safer to use something like k instead.

From the scripting book:

J(nrows, , )

Function: Creates a matrix of identical values.

Returns: The matrix.

Arguments:
nrows Number of rows in matrix. If ncols is not specified, nrows is also used as ncols.
ncols Number of columns in matrix.
value The value used to populate the matrix. If value is not specified, 1 is used.


Regards,
Peter
mpb

Super User

Joined:

Jun 23, 2011

> 3. I would not use the letter "j" as a variable,
> because j is a JSL function. It's safer to use
> something like k instead.

This is an interesting observation I hadn't thought of and it does seem it may be asking for trouble to use j as a variable. On the other hand the scripting docs have some examples where j is used as a subscript and one where j is the index in a For loop. The Jump into JMP Scripting book also has at least one example of a For loop indexing on i and j.

So I wonder if j (or J) without arguments may really be safe to use.