MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: For loop outputs to a list

  • To: mathgroup at
  • Subject: [mg112879] Re: For loop outputs to a list
  • From: "Nasser M. Abbasi" <nma at>
  • Date: Tue, 5 Oct 2010 05:31:11 -0400 (EDT)
  • References: <i8c90m$gd8$>
  • Reply-to: nma at

On 10/4/2010 3:07 AM, matthew wrote:
> For[i = 0, i<  10^6, i++,
>    If[Abs[Re[LS2[0.004 + i*Pre]] - Re[RS[0.004 + i*Pre]]]<  10^-7  ,
>     Print[N[0.004 + i*Pre]]
>      If[0.004 + i*Pre>  0.007, Break[]]
>     ]];

I can't read your code above, it seems missing something? after the 
Print[..] you have If[...], nothing in between?

Any way, assuming you trying to do

For[i = 0, i < 10^6, i++,
  If[..., result =. .., result =. ...]

Then you can try using a Table?

result = Table[{i, If[ ..., x , y ]}, {i, 0, 10^6-1}}]

If[] will have side effect the result that got computed as its value, 
i.e. weither x or y.  do not use Print[x], just leave x as is.

This will give a table with the first column having the value 'i' and 
the second column having the result found for that i.



  • Prev by Date: Re: How to apply a list of functions
  • Next by Date: More universal way of writing gradient
  • Previous by thread: For loop outputs to a list
  • Next by thread: Re: For loop outputs to a list