Hi Paul,

This is very strange. Have you tried stepping through this method in
the debugger to see what is happening? Perhaps the bug is not that the
loop runs twice, but that MonoDevelop's "Application Output" window is
wrong?

I've tried reproducing this locally using the following code:

float[] Premium = new float [10];
float m_TotalPremium;

public void CalculateOld ()
{
    Console.WriteLine("Calculate");

    m_TotalPremium = 0f;

    for (int i = 0; i < Premium.Length; i++)
    {
        Premium[i] = i * 10.00f;

        Console.WriteLine(i);

        if(true)
        {
            m_TotalPremium = m_TotalPremium + Premium[i];
        }
    }
}


Unfortunately I haven't been able to reproduce the double-loop running
in the iPhoneSimulator (I assume you're running on the Simulator and
not Device?)

I had to change things a slight bit from your pasted code because I do
not know the relationship between Coverage and Premiums, and this
might be why I'm unable to reproduce.

Any additional info you can provide me so that I'm able to reproduce
this would be really appreciated,

Jeff


On Wed, Feb 29, 2012 at 4:57 AM, PaulSinnema <[email protected]> wrote:
>
> I've changed the routine to this and now the result is correct. Very weird:
>
>                public void Calculate ()
>                {
>                        m_TotalPremium = 0f;
>
>                        CalculateTotalPremium ();
>
>                        m_TotalPremium = 0f;
>
>                        CalculateTotalPremium ();
>                }
>
>                void CalculateTotalPremium ()
>                {
>                        for (int i = 0; i < Coverage.Count; i++)
>                        {
>                                Premium[i] = i * 10.00f;
>
>                                if(Coverage[i])
>                                {
>                                        m_TotalPremium = m_TotalPremium + 
> Premium[i];
>                                }
>                        }
>                }
>
>
> --
> View this message in context: 
> http://monotouch.2284126.n4.nabble.com/Loop-runs-twice-tp4431082p4431099.html
> Sent from the MonoTouch mailing list archive at Nabble.com.
> _______________________________________________
> MonoTouch mailing list
> [email protected]
> http://lists.ximian.com/mailman/listinfo/monotouch
_______________________________________________
MonoTouch mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/monotouch

Reply via email to