I have a matrix A, which has its elements being function of m, say
A[m_]={m, -m*m+2, 5x+m, 3*m+2, -m*m*m, -3+m, m, 5*m*m-4*m, 2*m*m*m}
Now, there is a double For loop, as
For[m = 1, m < 6, m++,
For[k = 1, k < 9, k++,
If[A[m][[k]] < 0, Print[A[m][[k]], m]; Break[]]]]
This loop is meant to pick elements of the A one by one, if this element is negative, m -> m++ and A is calculated for new m value and so on..
My problem is that for every loop for m, k loop starts from 1. But I want it to start from next element for next cycle.
For example, for m = 1 loop, first negative element (-m*m+2) of A is at second position (k=2) so first o/p of code is 0. Now for next cycle of m, I want k to start values from element which is already picked, so it should start from 3, not from 1. Similarly after m = 2 loop, which has negative element at position 4, I want m = 3 cycle to start from k = 5 and so on... Would appreciate any help on this thanks
TableandDo. They're similar, but much nicer to work with. They're also faster andTableis often much faster as it auto-compiles. – b3m2a1 Dec 12 '17 at 05:39m = 1loop, the first negative element is-m^3 == -1at k == 5(not(-m*m+2)). Also, I'm assuming thex` in position 3 is a typo and can be ignored. – aardvark2012 Dec 12 '17 at 20:34