using for loop to find minimum values and saving results in a listI have three lists of numbers:
a= {2,3,4,5,6}
b = {4,5,7,2,1}
c= {9,6,4,6,2}
I would like to take the minimum of each index from the 3 lists and turn that into a list, say d. so d = {2,3,4,2,1}.
the loop i have started is:
minsl = {};
for(i = 1, i = 6, i++,
mins = {a[i], b[i], c[i]};
minval = minimum(mins);
minsl=insert into(minsl,minval,i);
If(n items(minsl)==5, break()); // this line was added to stop the loop because it gets stuck
);
the output is minsl = {1,1,1,1,1} i.e. is gets stuck storing the last entry in the list only (and foes on forever without the break line), when it should be {2,3,4,2,1}
Any suggestions how to fix?? Thanks!!
Automation and ScriptingRe: using for loop to find minimum values and saving results in a listdidn't think of this, good idea-thanks!
Re: using for loop to find minimum values and saving results in a listthanks!! 
Re: using for loop to find minimum values and saving results in a listYou can also use matrices + V Min() for this (remember to comment to code to make it easier to understand if needed)
Names Default To Here(1);
a = {2, 3, 4, 5, 6};
b = {4, 5, 7, 2, 1};
c = {9, 6, 4, 6, 2};
m = Matrix(a)` |/ Matrix(b)` |/ Matrix(c)`;
d = As List(V Min(m)`); // {2, 3, 4, 2, 1}
Re: using for loop to find minimum values and saving results in a listYour For() loop of
For( i = 1, i = 5, i++,
needs to be
For( i = 1, i <= 5, i++,
Then it seems to work the way you want it to
names default to here( 1 );
a = {2, 3, 4, 5, 6};
b = {4, 5, 7, 2, 1};
c = {9, 6, 4, 6, 2};
minsl = {};
For( i = 1, i <= 5, i++,
mins = a[i] || b[i] || c[i];
minval = Minimum( mins );
Insert Into( minsl, minval );
);Re: using for loop to find minimum values and saving results in a lista = {2, 3, 4, 5, 6};
b = {4, 5, 7, 2, 1};
c = {9, 6, 4, 6, 2};
minsl = {};
i = 1;
mins = {a[i],b[i],c[i]};
minval = minimum(mins);
insert into (minsl,minval,i);
i=2;
mins = {a[i],b[i],c[i]};
minval = minimum(mins);
insert into (minsl,minval,i);
i = 3;
mins = {a[i],b[i],c[i]};
minval = minimum(mins);
insert into (minsl,minval,i);
i = 4;
mins = {a[i],b[i],c[i]};
minval = minimum(mins);
insert into (minsl,minval,i);
minsli.e. the above works, but I would like to get a loop working for when I have lists of much longer lengths
Re: using for loop to find minimum values and saving results in a listthanks! this doesn't seem to preserve the order though. Essentially, I need to pull the minimum value out of the first index of the 3 lists and then store that in a list (preserving order)
a = {2, 3, 4, 5, 6};
b = {4, 5, 7, 2, 1};
c = {9, 6, 4, 6, 2};
minsl = {};
for(i = 1, i = 5, i++,
mins = {a[i],b[i],c[i]};
minval = minimum(mins);
insert into (minsl,minval,i);
If(n items(minsl)==5, break());
);if you run the above code ignoring the actual loop and do i=1, and then run just the inside of the loop and then put i=2 and run the inside of the loop it works (you'll see minsl = {2,3} )but for some reason the loop doesn't cycle properly and breaks
Re: using for loop to find minimum values and saving results in a listHere is how I would approach the issue
names default to here(1);
a = {2, 3, 4, 5, 6};
b = {4, 5, 7, 2, 1};
c = {9, 6, 4, 6, 2};
a1= sortlist(a);
remove from(a1,3,n=length(a)-2);
b1= sortlist(b);
remove from(b1,3,n=length(b)-2);
c1= sortlist(c);
remove from(c1,3,n=length(c)-2);
d=a1||b1||c1;
Also, please use the icon at the top of the Preview window when entering script code. It allows for the reader to more easily read the code.