<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Subscript range issue when doing increasing for loop in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Subscript-range-issue-when-doing-increasing-for-loop/m-p/621319#M82045</link>
    <description>&lt;P&gt;Hi TS,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yes, the error go away. However, I always use i&amp;lt;= N Cols (dt) and no issue at all. I dont understand why in this situation the same method failed?&lt;/P&gt;</description>
    <pubDate>Sun, 09 Apr 2023 19:04:51 GMT</pubDate>
    <dc:creator>dadawasozo</dc:creator>
    <dc:date>2023-04-09T19:04:51Z</dc:date>
    <item>
      <title>Subscript range issue when doing increasing for loop</title>
      <link>https://community.jmp.com/t5/Discussions/Subscript-range-issue-when-doing-increasing-for-loop/m-p/621305#M82043</link>
      <description>&lt;P&gt;I got error "Subscript Range in access or evaluation of 'collist[ /*###*/i]' , collist[/*###*/i]" when doing a simple new column () with increasing for loop. I able to solve it using decreasing for loop. However, I want to have created column ordered follow increasing for loop. I dont understand what causes the error when using increasing for loop here. Can someone provide suggestion how I can use increasing for loop here? if possible, can someone help explain why the error will happen for increasing for loop?&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;path = "my file path with filename.jmp";

dt= open(path);
collist = dt &amp;lt;&amp;lt;get column names(string);
colname = Column("test1") &amp;lt;&amp;lt;getname;
colnumber = (Loc(collist,colname))[1];

For(i=colnumber+1, i&amp;lt;=Ncols(dt),i++,  //give the error
//For(i=Ncols(dt), i&amp;gt;colnumber+1,i--,  fixed issue but created column order inverted

dt  &amp;lt;&amp;lt;new column("SG_"||collist[i], character);

);



&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 09 Jun 2023 16:07:39 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Subscript-range-issue-when-doing-increasing-for-loop/m-p/621305#M82043</guid>
      <dc:creator>dadawasozo</dc:creator>
      <dc:date>2023-06-09T16:07:39Z</dc:date>
    </item>
    <item>
      <title>Re: Subscript range issue when doing increasing for loop</title>
      <link>https://community.jmp.com/t5/Discussions/Subscript-range-issue-when-doing-increasing-for-loop/m-p/621310#M82044</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I think that your problem is that N Cols (dt) increases after each iteration of your loop. Therefore, your index value "i" exceeds the number of elements in your collist list.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suggest capturing the number of columns in dt outside the loop and using it as a fixed limit.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;path = "my file path with filename.jmp";

dt= open(path);
collist = dt &amp;lt;&amp;lt;get column names(string);
colname = Column("test1") &amp;lt;&amp;lt;getname;
colnumber = (Loc(collist,colname))[1];
num_col = N Cols (dt);

For(i=colnumber+1, i&amp;lt;=num_col,i++,  
   dt  &amp;lt;&amp;lt;new column("SG_"||collist[i], character);

);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Of note, I am unsure why the reverse loop works. You it should run into a similar issue with your collist variable.&lt;/P&gt;
&lt;P&gt;Let us know if that solve your issue.&lt;/P&gt;
&lt;P&gt;Best,&lt;/P&gt;
&lt;P&gt;TS&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 09 Apr 2023 17:06:39 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Subscript-range-issue-when-doing-increasing-for-loop/m-p/621310#M82044</guid>
      <dc:creator>Thierry_S</dc:creator>
      <dc:date>2023-04-09T17:06:39Z</dc:date>
    </item>
    <item>
      <title>Re: Subscript range issue when doing increasing for loop</title>
      <link>https://community.jmp.com/t5/Discussions/Subscript-range-issue-when-doing-increasing-for-loop/m-p/621319#M82045</link>
      <description>&lt;P&gt;Hi TS,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yes, the error go away. However, I always use i&amp;lt;= N Cols (dt) and no issue at all. I dont understand why in this situation the same method failed?&lt;/P&gt;</description>
      <pubDate>Sun, 09 Apr 2023 19:04:51 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Subscript-range-issue-when-doing-increasing-for-loop/m-p/621319#M82045</guid>
      <dc:creator>dadawasozo</dc:creator>
      <dc:date>2023-04-09T19:04:51Z</dc:date>
    </item>
    <item>
      <title>Re: Subscript range issue when doing increasing for loop</title>
      <link>https://community.jmp.com/t5/Discussions/Subscript-range-issue-when-doing-increasing-for-loop/m-p/621328#M82046</link>
      <description>&lt;P&gt;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/11634"&gt;@Thierry_S&lt;/a&gt;&amp;nbsp; the reverse loop captures ncols(dt) at the start of the loop, exactly once.&lt;/P&gt;
&lt;P&gt;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/16303"&gt;@dadawasozo&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;the reverse loop isn't quite the same because it uses &amp;gt;colnumber+1 and probably should be &amp;gt;=colnumber+1 to match the non-working forward loop.&lt;/LI&gt;
&lt;LI&gt;In the forward loop, ncols(dt) is re-evaluated each time it loops and keeps getting bigger, but collist is not getting bigger, so eventually the subscript fails.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;I like &lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/11634"&gt;@Thierry_S&lt;/a&gt;&amp;nbsp; solution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 09 Apr 2023 21:17:54 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Subscript-range-issue-when-doing-increasing-for-loop/m-p/621328#M82046</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2023-04-09T21:17:54Z</dc:date>
    </item>
  </channel>
</rss>

