<?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: For loop not working as intended in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/For-loop-not-working-as-intended/m-p/533963#M75667</link>
    <description>&lt;P&gt;This was literally my second attempt out of all of this, and I came back to it over the weekend again and it worked.&amp;nbsp; I don't have an explanation as to why it didn't work the first time I tried it like this.&amp;nbsp; Thank you for your response!&lt;/P&gt;</description>
    <pubDate>Mon, 15 Aug 2022 18:48:12 GMT</pubDate>
    <dc:creator>StarfruitBob</dc:creator>
    <dc:date>2022-08-15T18:48:12Z</dc:date>
    <item>
      <title>For loop not working as intended</title>
      <link>https://community.jmp.com/t5/Discussions/For-loop-not-working-as-intended/m-p/533334#M75626</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have 2 very perplexing problems.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1 )&amp;nbsp; For the simple for loop below, I have 3 conditions that are met for a single output. I've verified by looking manually and graphing that all 8 combinations are indeed present in the data.&amp;nbsp; However, this comes out lopsided, where only x1, x2 and x3 will populate in all cells in the X1 column. The entry x2, for example, will have double the number of entries assigned to it. Upon further inspection via subset, A1, B1 and C1 columns are indeed met for both x2 and x4, which would be in equal shares. All columns share the same data &amp;amp; modeling type.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've also blocked out the entry that is gathering double the entries, just to see what will happen. Then the entries are bundled into x2, for example.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;For( i = 1, i &amp;lt;= N Rows ( dt ), i++,
	If( :A1[i] == "a1" &amp;amp; :B1[i] == "b1" &amp;amp; :C1[i] == "c1", :X1[i] = "x1";
	:A1[i] == "a1" &amp;amp; :B1[i] == "b1" &amp;amp; :C1[i] == "c2", :X1[i] = "x2";
	:A1[i] == "a1" &amp;amp; :B1[i] == "b2" &amp;amp; :C1[i] == "c1", :X1[i] = "x3";
	:A1[i] == "a1" &amp;amp; :B1[i] == "b2" &amp;amp; :C1[i] == "c2", :X1[i] = "x4";
	:A1[i] == "a2" &amp;amp; :B1[i] == "b1" &amp;amp; :C1[i] == "c1", :X1[i] = "x3";
	:A1[i] == "a2" &amp;amp; :B1[i] == "b1" &amp;amp; :C1[i] == "c2", :X1[i] = "x4";
	:A1[i] == "a2" &amp;amp; :B1[i] == "b2" &amp;amp; :C1[i] == "c1", :X1[i] = "x1";
	:A1[i] == "a2" &amp;amp; :B1[i] == "b2" &amp;amp; :C1[i] == "c2", :X1[i] = "x2";
	);
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2) If I shorten the code by assigning values to cell with &amp;amp;, I get an error "attempting to assign to an object that is not an L-value". This is an attempt to shorten my code and not have multiple different loops.&amp;nbsp; Below is an example of 3 criterion, and 3 outputs.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;For( i = 1, i &amp;lt;= N Rows ( dt ), i++,
	If( :A1[i] == "a1" &amp;amp; :B1[i] == "b1" &amp;amp; :C1[i] == "c1", :X1[i] = "x1" &amp;amp; :Y1[i] = "y1" &amp;amp; :Z1[i] = "z2";
	:A1[i] == "a1" &amp;amp; :B1[i] == "b1" &amp;amp; :C1[i] == "c2", :X1[i] = "x2" &amp;amp; :Y1[i] = "y3" &amp;amp; :Z1[i] = "z3";
	:A1[i] == "a1" &amp;amp; :B1[i] == "b2" &amp;amp; :C1[i] == "c1", :X1[i] = "x3" &amp;amp; :Y1[i] = "y2" &amp;amp; :Z1[i] = "z1";
	:A1[i] == "a1" &amp;amp; :B1[i] == "b2" &amp;amp; :C1[i] == "c2", :X1[i] = "x4" &amp;amp; :Y1[i] = "y4" &amp;amp; :Z1[i] = "z4";
	:A1[i] == "a2" &amp;amp; :B1[i] == "b1" &amp;amp; :C1[i] == "c1", :X1[i] = "x3" &amp;amp; :Y1[i] = "y1" &amp;amp; :Z1[i] = "z1";
	:A1[i] == "a2" &amp;amp; :B1[i] == "b1" &amp;amp; :C1[i] == "c2", :X1[i] = "x4" &amp;amp; :Y1[i] = "y2" &amp;amp; :Z1[i] = "z4";
	:A1[i] == "a2" &amp;amp; :B1[i] == "b2" &amp;amp; :C1[i] == "c1", :X1[i] = "x1" &amp;amp; :Y1[i] = "y4" &amp;amp; :Z1[i] = "z2";
	:A1[i] == "a2" &amp;amp; :B1[i] == "b2" &amp;amp; :C1[i] == "c2", :X1[i] = "x2" &amp;amp; :Y1[i] = "y3" &amp;amp; :Z1[i] = "z3";
	);
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Any guidance would be appreciated. Thank you for your help in advanced!&lt;/P&gt;</description>
      <pubDate>Sun, 11 Jun 2023 11:27:03 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/For-loop-not-working-as-intended/m-p/533334#M75626</guid>
      <dc:creator>StarfruitBob</dc:creator>
      <dc:date>2023-06-11T11:27:03Z</dc:date>
    </item>
    <item>
      <title>Re: For loop not working as intended</title>
      <link>https://community.jmp.com/t5/Discussions/For-loop-not-working-as-intended/m-p/533347#M75627</link>
      <description>&lt;P&gt;I've also made sure that the column names are called correctly in the code and I've tried both commas and semi-colons at the end of a line. I've broken the code into smaller chunks, separating the possible values in column A1 into different for loops, but I have the same issue.&lt;/P&gt;</description>
      <pubDate>Fri, 12 Aug 2022 22:10:11 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/For-loop-not-working-as-intended/m-p/533347#M75627</guid>
      <dc:creator>StarfruitBob</dc:creator>
      <dc:date>2022-08-12T22:10:11Z</dc:date>
    </item>
    <item>
      <title>Re: For loop not working as intended</title>
      <link>https://community.jmp.com/t5/Discussions/For-loop-not-working-as-intended/m-p/533355#M75628</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/39919"&gt;@StarfruitBob&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;You are close...&lt;/P&gt;
&lt;P&gt;The syntax for an&lt;A title="JMP JSL If Function Syntax" href="https://www.jmp.com/support/help/en/16.2/index.shtml#page/jmp/if.shtml" target="_self"&gt; if function&lt;/A&gt; is &amp;nbsp;If( condition 1, result1, condition 2, result 2, else result ).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So reworking your statement by replacing the trailing semicolon with a comma:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;For( i = 1, i &amp;lt;= N Rows ( dt ), i++,
	If(
	// condition 1 =  :A1[i] == "a1" &amp;amp; :B1[i] == "b1" &amp;amp; :C1[i] == "c1"
	// result 1 = :X1[i] = "x1" &amp;amp; :Y1[i] = "y1" &amp;amp; :Z1[i] = "z2"
		:A1[i] == "a1" &amp;amp; :B1[i] == "b1" &amp;amp; :C1[i] == "c1", :X1[i] = "x1" &amp;amp; :Y1[i] = "y1" &amp;amp; :Z1[i] = "z2"
	,
		:A1[i] == "a1" &amp;amp; :B1[i] == "b1" &amp;amp; :C1[i] == "c2", :X1[i] = "x2" &amp;amp; :Y1[i] = "y3" &amp;amp; :Z1[i] = "z3"
	,
		:A1[i] == "a1" &amp;amp; :B1[i] == "b2" &amp;amp; :C1[i] == "c1", :X1[i] = "x3" &amp;amp; :Y1[i] = "y2" &amp;amp; :Z1[i] = "z1"
	,
		:A1[i] == "a1" &amp;amp; :B1[i] == "b2" &amp;amp; :C1[i] == "c2", :X1[i] = "x4" &amp;amp; :Y1[i] = "y4" &amp;amp; :Z1[i] = "z4"
	,
		:A1[i] == "a2" &amp;amp; :B1[i] == "b1" &amp;amp; :C1[i] == "c1", :X1[i] = "x3" &amp;amp; :Y1[i] = "y1" &amp;amp; :Z1[i] = "z1"
	,
		:A1[i] == "a2" &amp;amp; :B1[i] == "b1" &amp;amp; :C1[i] == "c2", :X1[i] = "x4" &amp;amp; :Y1[i] = "y2" &amp;amp; :Z1[i] = "z4"
	,
		:A1[i] == "a2" &amp;amp; :B1[i] == "b2" &amp;amp; :C1[i] == "c1", :X1[i] = "x1" &amp;amp; :Y1[i] = "y4" &amp;amp; :Z1[i] = "z2"
	,
		:A1[i] == "a2" &amp;amp; :B1[i] == "b2" &amp;amp; :C1[i] == "c2", :X1[i] = "x2" &amp;amp; :Y1[i] = "y3" &amp;amp; :Z1[i] = "z3"
	);
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;HTH.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;cheers,&lt;/P&gt;
&lt;P&gt;Stan&lt;/P&gt;</description>
      <pubDate>Fri, 12 Aug 2022 22:24:53 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/For-loop-not-working-as-intended/m-p/533355#M75628</guid>
      <dc:creator>stan_koprowski</dc:creator>
      <dc:date>2022-08-12T22:24:53Z</dc:date>
    </item>
    <item>
      <title>Re: For loop not working as intended</title>
      <link>https://community.jmp.com/t5/Discussions/For-loop-not-working-as-intended/m-p/533359#M75629</link>
      <description>&lt;P&gt;Hello Stan,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your rapid reply!&amp;nbsp; This is something I've already experimented with and instead of x1, x2, and x3 populating, x1, x2, and x4 will populate, for example.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This also happens with multiple outputs, such as column X1 and Y1.&lt;/P&gt;</description>
      <pubDate>Fri, 12 Aug 2022 22:30:17 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/For-loop-not-working-as-intended/m-p/533359#M75629</guid>
      <dc:creator>StarfruitBob</dc:creator>
      <dc:date>2022-08-12T22:30:17Z</dc:date>
    </item>
    <item>
      <title>Re: For loop not working as intended</title>
      <link>https://community.jmp.com/t5/Discussions/For-loop-not-working-as-intended/m-p/533371#M75632</link>
      <description>&lt;P&gt;Yes, make sure you use the commas like Stan suggests. &lt;LI-MESSAGE title="If Secrets" uid="39558" url="https://community.jmp.com/t5/Uncharted/If-Secrets/m-p/39558#U39558" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-blog-thread lia-fa-icon lia-fa-blog lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit: I think you want&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;If( :A1[i] == "a1" &amp;amp; :B1[i] == "b1" &amp;amp; :C1[i] == "c1" , :X1[i] = "x1" ,
	:A1[i] == "a1" &amp;amp; :B1[i] == "b1" &amp;amp; :C1[i] == "c2" , :X1[i] = "x2" ,
	:A1[i] == "a1" &amp;amp; :B1[i] == "b2" &amp;amp; :C1[i] == "c1" , :X1[i] = "x3" ,
	:A1[i] == "a1" &amp;amp; :B1[i] == "b2" &amp;amp; :C1[i] == "c2" , :X1[i] = "x4" ,
	:A1[i] == "a2" &amp;amp; :B1[i] == "b1" &amp;amp; :C1[i] == "c1" , :X1[i] = "x3" ,
	:A1[i] == "a2" &amp;amp; :B1[i] == "b1" &amp;amp; :C1[i] == "c2" , :X1[i] = "x4" ,
	:A1[i] == "a2" &amp;amp; :B1[i] == "b2" &amp;amp; :C1[i] == "c1" , :X1[i] = "x1" ,
	:A1[i] == "a2" &amp;amp; :B1[i] == "b2" &amp;amp; :C1[i] == "c2" , :X1[i] = "x2" ,
    throw("Nothing matched!") // this is the otherwise case 
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you really want multiple assignments, use ; rather than &amp;amp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;:X1[i] = "x1" &amp;amp; :Y1[i] = "y1" &amp;amp; :Z1[i] = "z2" // change this

:X1[i] = "x1"; :Y1[i] = "y1"; :Z1[i] = "z2";  // to this&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;STRIKE&gt;While it might work with &amp;amp; it will be very fragile and very hard for the next person to puzzle out. &lt;/STRIKE&gt; As you say, the compiler sees &lt;STRIKE&gt;&lt;/STRIKE&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;a=1 &amp;amp; b=2&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;as&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;a = ( ( 1 &amp;amp; b ) = 2 )&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;which produces the L-value message. It would be nice if the error message wasn't programmer speak for &lt;EM&gt;I can't store the value 2 from the right side of the = into "1 &amp;amp; b" on the left side of the = because "1 &amp;amp; b" is not a variable name&lt;/EM&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Actually, the compiler does a reasonably good job for a=1 &amp;amp; b=2:&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;attempting to assign to an object that is not an L-value in access or evaluation of 'Assign' , 1 &amp;amp; b = /*###*/2 /*###*/&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 13 Aug 2022 00:49:00 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/For-loop-not-working-as-intended/m-p/533371#M75632</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2022-08-13T00:49:00Z</dc:date>
    </item>
    <item>
      <title>Re: For loop not working as intended</title>
      <link>https://community.jmp.com/t5/Discussions/For-loop-not-working-as-intended/m-p/533963#M75667</link>
      <description>&lt;P&gt;This was literally my second attempt out of all of this, and I came back to it over the weekend again and it worked.&amp;nbsp; I don't have an explanation as to why it didn't work the first time I tried it like this.&amp;nbsp; Thank you for your response!&lt;/P&gt;</description>
      <pubDate>Mon, 15 Aug 2022 18:48:12 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/For-loop-not-working-as-intended/m-p/533963#M75667</guid>
      <dc:creator>StarfruitBob</dc:creator>
      <dc:date>2022-08-15T18:48:12Z</dc:date>
    </item>
  </channel>
</rss>

