<?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 question in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/For-loop-question/m-p/228314#M45299</link>
    <description>&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/982"&gt;@Craige_Hales&lt;/a&gt;, &lt;BR /&gt;Oooh!  I missed that he was looking for multiple entries in the same field... Thanks for setting me straight!&lt;BR /&gt;&lt;BR /&gt;M</description>
    <pubDate>Mon, 07 Oct 2019 13:51:02 GMT</pubDate>
    <dc:creator>MikeD_Anderson</dc:creator>
    <dc:date>2019-10-07T13:51:02Z</dc:date>
    <item>
      <title>For loop question</title>
      <link>https://community.jmp.com/t5/Discussions/For-loop-question/m-p/228123#M45255</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;
&lt;P&gt;First time I'm writing here, though I&amp;nbsp;have read in&amp;nbsp;this forum a lot.&lt;/P&gt;
&lt;P&gt;I do have some experience in JSL scripting, but I still haven't dealt with for loops.&lt;/P&gt;
&lt;P&gt;I have this data table which has 5 columns: entity, date1, date2, value1,&amp;nbsp;value2 (value2 column initially&amp;nbsp;contains missing values only).&lt;/P&gt;
&lt;P&gt;The table is sorted by Entity (ascending) and&amp;nbsp;date1 (descending).&lt;/P&gt;
&lt;P&gt;I want to loop through all rows, and insert values from value1 column into value2 column, based on&amp;nbsp;the following condition:&lt;/P&gt;
&lt;P&gt;IF entity[row i] == entity[row j] AND date1[row i] &amp;gt; date2[row j] THEN insert the value from value1[row j] into value2[row i]&lt;/P&gt;
&lt;P&gt;Once a value is inserted,&amp;nbsp;just continue to the next row.&lt;/P&gt;
&lt;P&gt;So far I have this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = Current Data Table();

For( i = 1, i &amp;lt;= N Rows( dt ), i++, 
	For( j = i, j &amp;lt;= N Rows( dt ), j++, 
		If(
			And(
				Column( dt, "entity" )[i] == Column( dt, "entity" )[j],
				Column( dt, "date1" )[i] &amp;gt; Column( dt, "date2" )[j]
			), 
			Column( dt, "value2" )[i] = Column( dt, "value1" )[j];
			Break();
		)
	)
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Consolas" size="2" color="#000080"&gt;But I'm not getting any values inserted to value2.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Consolas" size="2" color="#000080"&gt;I would love to get some help on this. Hope I explained myself well.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Consolas" size="2" color="#000080"&gt;Thanks&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Oct 2019 19:21:23 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/For-loop-question/m-p/228123#M45255</guid>
      <dc:creator>Yotam</dc:creator>
      <dc:date>2019-10-04T19:21:23Z</dc:date>
    </item>
    <item>
      <title>Re: For loop question</title>
      <link>https://community.jmp.com/t5/Discussions/For-loop-question/m-p/228133#M45256</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/16254"&gt;@Yotam&lt;/a&gt;&amp;nbsp;!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'd start by using the For Each Row() construct in the data table. &amp;nbsp;It's a lot easier to use when you're looping throgh a data table. &amp;nbsp;Also, I think you only need one loop, since your indexing on row not through two lists with different lengths. &amp;nbsp;Some of my favorite resources on the topic are below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://community.jmp.com/t5/JSL-Cookbook/Loops/ta-p/50949" target="_blank" rel="noopener"&gt;https://community.jmp.com/t5/JSL-Cookbook/Loops/ta-p/50949&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://www.jmp.com/support/help/14-2/iterate-on-rows-in-a-table.shtml" target="_blank" rel="noopener"&gt;https://www.jmp.com/support/help/14-2/iterate-on-rows-in-a-table.shtml&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;M&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Update:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think this code will do what you want:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;// Name the data table
dt = Current Data Table();

//For each row compare the dates and populate value 2 with value 1 if they are equal.
For Each Row( dt, If( :date1 == :date2, :value2 = :value1 ) );&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also, the first line of your code is missing the glue (;) which may be causing you a problem. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;M&lt;/P&gt;</description>
      <pubDate>Fri, 04 Oct 2019 15:54:23 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/For-loop-question/m-p/228133#M45256</guid>
      <dc:creator>MikeD_Anderson</dc:creator>
      <dc:date>2019-10-04T15:54:23Z</dc:date>
    </item>
    <item>
      <title>Re: For loop question</title>
      <link>https://community.jmp.com/t5/Discussions/For-loop-question/m-p/228134#M45257</link>
      <description>&lt;P&gt;I created a data table like what you described and ran your script against, and I did get some values inserted into the value2 column. Is it possible that your table just doesn't have any values that meet your conditions?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is what I did:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Created a table with these five columns and 100 rows.&lt;/LI&gt;
&lt;LI&gt;Column 1 is entity, and I filled it with Random Integers between 1-100. (so some values are repeated, some values don't appear.)&lt;/LI&gt;
&lt;LI&gt;Column 2 is date1. I made it y/m/d and filled with sequence data (incrementing every day) from October 1, 2019 to January 8, 2020.&lt;/LI&gt;
&lt;LI&gt;Column 3 is date2. I made it y/m/d and filled it with Random Integers that matched the date range in date1. (so some days are repeated, some days don't appear.)&lt;/LI&gt;
&lt;LI&gt;Column 4 is value1. I filled with with Random Uniform between 0 and 1.&lt;/LI&gt;
&lt;LI&gt;Column 5 is value2, left empty.&lt;/LI&gt;
&lt;LI&gt;I sorted date1 descending, and then I sorted entity ascending.&lt;/LI&gt;
&lt;LI&gt;Then I ran your script, and it did populate some rows in value2 with values from value1.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the script for the table I created:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;New Table( "Untitled",
	Add Rows( 100 ),
	New Column( "entity",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Values(
			[1, 1, 2, 5, 7, 8, 10, 11, 12, 12, 13, 14, 14, 15, 16, 17, 17, 18, 20,
			21, 21, 23, 25, 25, 26, 26, 30, 30, 31, 32, 33, 35, 37, 38, 38, 39, 40,
			41, 42, 45, 48, 48, 48, 49, 49, 49, 49, 49, 50, 50, 54, 54, 55, 55, 55,
			56, 56, 57, 57, 61, 64, 65, 66, 66, 67, 67, 68, 71, 72, 73, 73, 75, 76,
			77, 77, 79, 79, 79, 80, 81, 83, 84, 85, 85, 85, 86, 87, 88, 90, 92, 92,
			93, 94, 95, 95, 96, 97, 98, 98, 98]
		)
	),
	New Column( "date1",
		Numeric,
		"Continuous",
		Format( "y/m/d", 12 ),
		Input Format( "y/m/d" ),
		Set Values(
			[3660595200, 3653596800, 3655324800, 3657916800, 3657571200, 3659904000,
			3655670400, 3658867200, 3660768000, 3655843200, 3655497600, 3661286400,
			3657139200, 3659817600, 3657744000, 3655411200, 3653078400, 3656448000,
			3653856000, 3659299200, 3654374400, 3653251200, 3656707200, 3654115200,
			3659212800, 3655756800, 3654979200, 3654288000, 3654201600, 3660249600,
			3658176000, 3657225600, 3653510400, 3658608000, 3654892800, 3658780800,
			3654806400, 3656188800, 3659040000, 3659990400, 3657657600, 3656880000,
			3652992000, 3659644800, 3658089600, 3655238400, 3654028800, 3653164800,
			3658348800, 3652992000, 3659385600, 3656102400, 3659558400, 3657312000,
			3655929600, 3653424000, 3653337600, 3657484800, 3656016000, 3661113600,
			3653164800, 3660854400, 3660076800, 3655152000, 3661027200, 3658435200,
			3656620800, 3654547200, 3656534400, 3657830400, 3657052800, 3654633600,
			3660163200, 3658953600, 3653078400, 3660422400, 3658262400, 3655065600,
			3658694400, 3658521600, 3655584000, 3659731200, 3659472000, 3659126400,
			3653769600, 3654460800, 3660681600, 3660940800, 3660508800, 3653942400,
			3653683200, 3656361600, 3658003200, 3660336000, 3656966400, 3656793600,
			3654720000, 3661200000, 3657398400, 3656275200]
		)
	),
	New Column( "date2",
		Numeric,
		"Continuous",
		Format( "y/m/d", 12 ),
		Input Format( "y/m/d" ),
		Set Values(
			[3654288000, 3654547200, 3660940800, 3655238400, 3655756800, 3653078400,
			3655152000, 3661113600, 3655670400, 3658521600, 3657916800, 3660854400,
			3660336000, 3655497600, 3654288000, 3658867200, 3655929600, 3658780800,
			3654460800, 3654288000, 3659472000, 3654374400, 3655584000, 3658435200,
			3661286400, 3655843200, 3657484800, 3657225600, 3654460800, 3659040000,
			3659904000, 3657744000, 3656016000, 3661113600, 3660854400, 3658435200,
			3656275200, 3658953600, 3660508800, 3660940800, 3654892800, 3654374400,
			3656966400, 3655065600, 3656620800, 3656448000, 3653424000, 3657312000,
			3653596800, 3653078400, 3659126400, 3658089600, 3661027200, 3655929600,
			3660249600, 3656102400, 3659040000, 3655411200, 3656275200, 3657916800,
			3654979200, 3658176000, 3657830400, 3657830400, 3658867200, 3659644800,
			3655670400, 3658262400, 3658867200, 3655584000, 3653942400, 3658435200,
			3656448000, 3657571200, 3654201600, 3656620800, 3658262400, 3656620800,
			3658262400, 3660595200, 3661200000, 3660595200, 3654028800, 3653078400,
			3659990400, 3659817600, 3659558400, 3659817600, 3654201600, 3656534400,
			3656707200, 3660508800, 3656102400, 3658003200, 3654979200, 3653683200,
			3659126400, 3654115200, 3660595200, 3657830400]
		)
	),
	New Column( "value1",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Values(
			[0.26654487522319, 0.268102226778865, 0.0855446415953338,
			0.573256081901491, 0.356754610314965, 0.754618955776095,
			0.707293681567535, 0.423604927491397, 0.0621724124066532,
			0.678517441963777, 0.591030938085169, 0.155546535504982,
			0.265113049885258, 0.216979010729119, 0.410901310387999,
			0.14603908569552, 0.672683654818684, 0.615730489837006,
			0.283979720901698, 0.569958938285708, 0.395094690844417,
			0.740726810414344, 0.69660765840672, 0.592704318463802,
			0.0819160102400928, 0.951408985769376, 0.622255727648735,
			0.666835095966235, 0.735137741314247, 0.302926567615941,
			0.135769379558042, 0.909960085060447, 0.159030285663903,
			0.721727871336043, 0.084829821716994, 0.133812531363219,
			0.775578187312931, 0.721618666080758, 0.824164194054901,
			0.791532889008522, 0.596487301168963, 0.432518238201737,
			0.803037486504763, 0.963547020917758, 0.483634022762999,
			0.256266842130572, 0.184637202415615, 0.368785659084097,
			0.433026649756357, 0.322859298205003, 0.63024612586014,
			0.366389756789431, 0.31168167036958, 0.215982228284702,
			0.506428832421079, 0.914496833458543, 0.00391270662657917,
			0.911203439114615, 0.158799458295107, 0.0707558316644281,
			0.0671632892917842, 0.626141374465078, 0.481671805493534,
			0.175614738604054, 0.345019530970603, 0.998095875838771,
			0.88658848637715, 0.352987453807145, 0.427561661927029,
			0.664279501885176, 0.0914310747757554, 0.8409428098239,
			0.483058925019577, 0.812691684346646, 0.184209692059085,
			0.956565208500251, 0.133405604865402, 0.358119377400726,
			0.416565118124708, 0.289288628380746, 0.51707451720722,
			0.294909303309396, 0.108170761261135, 0.084945646347478,
			0.978223626734689, 0.369202323025092, 0.00625932472757995,
			0.590033906744793, 0.253290069289505, 0.313401067862287, 0.4109431670513,
			0.178761875722557, 0.781808004016057, 0.686178727308288,
			0.0606778394430876, 0.432180172763765, 0.761295787990093,
			0.578681491082534, 0.197850840399042, 0.98485347116366]
		)
	),
	New Column( "value2",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
	)
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If this isn't like your table, what is your table like?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;HTH,&lt;/P&gt;
&lt;P&gt;Melanie&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Oct 2019 15:46:57 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/For-loop-question/m-p/228134#M45257</guid>
      <dc:creator>Melanie_J_Drake</dc:creator>
      <dc:date>2019-10-04T15:46:57Z</dc:date>
    </item>
    <item>
      <title>Re: For loop question</title>
      <link>https://community.jmp.com/t5/Discussions/For-loop-question/m-p/228217#M45270</link>
      <description>&lt;P&gt;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/4530"&gt;@MikeD_Anderson&lt;/a&gt;&amp;nbsp;I think it is using the nested loops on purpose. The &lt;EM&gt;break()&lt;/EM&gt; in the inner loop should help find the first future row to copy a value from and then stop testing more future rows.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/16254"&gt;@Yotam&lt;/a&gt;&amp;nbsp;you might need to make the &lt;EM&gt;break()&lt;/EM&gt; for another case as well: a second &lt;EM&gt;if&lt;/EM&gt; statement for &lt;EM&gt;entity[i] != entity[j]&lt;/EM&gt;. This is not the solution to the current problem, but if your table gets very large, the inner loop should not have to run to the end of the table for the last entity in each entity group. The run time could go from N^2 to linear.&lt;/P&gt;&lt;P&gt;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/4451"&gt;@Melanie_J_Drake&lt;/a&gt;&amp;nbsp;Good use of the date column. Possibly the original columns were character, and strings like "9JAN2019" and "10JAN2019" would not compare the same as their date values.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 05 Oct 2019 13:04:23 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/For-loop-question/m-p/228217#M45270</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2019-10-05T13:04:23Z</dc:date>
    </item>
    <item>
      <title>Re: For loop question</title>
      <link>https://community.jmp.com/t5/Discussions/For-loop-question/m-p/228218#M45271</link>
      <description>&lt;P&gt;Thanks to everyone for responding!&lt;/P&gt;&lt;P&gt;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/4530"&gt;@MikeD_Anderson&lt;/a&gt;&amp;nbsp;Maybe I misunderstood you, but I think I do need the nested loop, because for each row I'm testing the values from different rows as well, so I think I do need those indexes (i,j).&lt;/P&gt;&lt;P&gt;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/4451"&gt;@Melanie_J_Drake&lt;/a&gt;&amp;nbsp;After you gave your example table and said it was working, I tried to figure out what is going wrong with my data. My table did have values that met&amp;nbsp;the conditions, so I was pretty puzzled.&amp;nbsp;Turns out that before the loop I added the new column for value2 (just with missing values) incorrectly.&lt;/P&gt;&lt;P&gt;Here is what I did at first:&lt;/P&gt;&lt;P&gt;&lt;FONT face="Consolas" size="2"&gt;dt&lt;/FONT&gt;&lt;FONT color="#000080" face="Consolas" size="2"&gt;&amp;lt;&amp;lt;&lt;STRONG&gt;New Column&lt;/STRONG&gt;&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Consolas" size="2"&gt;(&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT color="#800080" face="Consolas" size="2"&gt;"last_lot_thickness"&lt;/FONT&gt;&lt;FONT color="#000080" face="Consolas" size="2"&gt;,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Consolas" size="2"&gt;Numeric&lt;/FONT&gt;&lt;FONT color="#000080" face="Consolas" size="2"&gt;,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Consolas" size="2"&gt;Continuous&lt;/FONT&gt;&lt;FONT color="#000080" face="Consolas" size="2"&gt;,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000dd" face="Consolas" size="2"&gt;Format&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Consolas" size="2"&gt;(&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#800080" face="Consolas" size="2"&gt;"Best"&lt;/FONT&gt;&lt;FONT color="#000080" face="Consolas" size="2"&gt;,&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#008080" face="Consolas" size="2"&gt;12&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Consolas" size="2"&gt; &lt;STRONG&gt;)&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT color="#000080" face="Consolas" size="2"&gt;,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Consolas" size="2"&gt;Formula&lt;STRONG&gt;(&lt;/STRONG&gt;&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Consolas" size="2"&gt;.&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;))&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT color="#000080" face="Consolas" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It took me some time to&amp;nbsp;understand that this was the reason I was not getting values into value2 during the loop.&amp;nbsp;Only when I did the&amp;nbsp;following I got my result:&lt;/P&gt;&lt;P&gt;&lt;FONT face="Consolas" size="2"&gt;dt&lt;/FONT&gt;&lt;FONT color="#000080" face="Consolas" size="2"&gt;&amp;lt;&amp;lt;&lt;STRONG&gt;New Column&lt;/STRONG&gt;&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Consolas" size="2"&gt;(&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT color="#800080" face="Consolas" size="2"&gt;"value2"&lt;/FONT&gt;&lt;FONT color="#000080" face="Consolas" size="2"&gt;,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Consolas" size="2"&gt;Numeric&lt;/FONT&gt;&lt;FONT color="#000080" face="Consolas" size="2"&gt;,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Consolas" size="2"&gt;Continuous&lt;/FONT&gt;&lt;FONT color="#000080" face="Consolas" size="2"&gt;,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000dd" face="Consolas" size="2"&gt;Format&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Consolas" size="2"&gt;(&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#800080" face="Consolas" size="2"&gt;"Best"&lt;/FONT&gt;&lt;FONT color="#000080" face="Consolas" size="2"&gt;,&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#008080" face="Consolas" size="2"&gt;12&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Consolas" size="2"&gt; &lt;STRONG&gt;))&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT color="#000080" face="Consolas" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I actually still don't understand what difference does it make, but turns out it solved the problem. Do you have any idea why?&lt;/P&gt;&lt;P&gt;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/982"&gt;@Craige_Hales&lt;/a&gt;&amp;nbsp;I'm not sure I completely understood what you said. My table is about 30,000 rows and it actually does take some time for the script to run. Could you be more specific where you would put the extra&amp;nbsp;break?&lt;/P&gt;&lt;P&gt;Thanks to all!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 05 Oct 2019 15:12:06 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/For-loop-question/m-p/228218#M45271</guid>
      <dc:creator>Yotam</dc:creator>
      <dc:date>2019-10-05T15:12:06Z</dc:date>
    </item>
    <item>
      <title>Re: For loop question</title>
      <link>https://community.jmp.com/t5/Discussions/For-loop-question/m-p/228219#M45272</link>
      <description>&lt;P&gt;the speed up; it even helps with Melanie's small example:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = Current Data Table();
start=tickseconds();
For( i = 1, i &amp;lt;= N Rows( dt ), i++, 
	For( j = i, j &amp;lt;= N Rows( dt ), j++, 
		If(
			And(
				Column( dt, "entity" )[i] == Column( dt, "entity" )[j],
				Column( dt, "date1" )[i] &amp;gt; Column( dt, "date2" )[j]
			), 
			Column( dt, "value2" )[i] = Column( dt, "value1" )[j];
			Break();
		);
		if(dt:entity[i]!=dt:entity[j],break());// speedup
	)
);
show(tickseconds()-start)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;since the entity values are sorted, no need to study all the following rows where they can't match.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The answer for the question you directed to Melanie: putting &lt;EM&gt;formula(.)&lt;/EM&gt; in the column specification makes the column a formula column. A formula column has no data of its own; it uses the formula expression (a missing value in your example) to compute the value. A more typical formula would use other columns, but constants are OK too. It does seem like you should get a log message when assigning to a formula column.&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/11257"&gt;@EvanMcCorkle&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 05 Oct 2019 16:04:39 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/For-loop-question/m-p/228219#M45272</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2019-10-05T16:04:39Z</dc:date>
    </item>
    <item>
      <title>Re: For loop question</title>
      <link>https://community.jmp.com/t5/Discussions/For-loop-question/m-p/228220#M45273</link>
      <description>&lt;P&gt;I got it! You are absolutely right, it saves a lot of time. Thanks!&lt;/P&gt;</description>
      <pubDate>Sat, 05 Oct 2019 17:18:12 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/For-loop-question/m-p/228220#M45273</guid>
      <dc:creator>Yotam</dc:creator>
      <dc:date>2019-10-05T17:18:12Z</dc:date>
    </item>
    <item>
      <title>Re: For loop question</title>
      <link>https://community.jmp.com/t5/Discussions/For-loop-question/m-p/228314#M45299</link>
      <description>&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/982"&gt;@Craige_Hales&lt;/a&gt;, &lt;BR /&gt;Oooh!  I missed that he was looking for multiple entries in the same field... Thanks for setting me straight!&lt;BR /&gt;&lt;BR /&gt;M</description>
      <pubDate>Mon, 07 Oct 2019 13:51:02 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/For-loop-question/m-p/228314#M45299</guid>
      <dc:creator>MikeD_Anderson</dc:creator>
      <dc:date>2019-10-07T13:51:02Z</dc:date>
    </item>
  </channel>
</rss>

