C#:For循环只迭代一个不完整的循环

时间:2018-03-25 08:02:00

标签: c#

我有一些问题:

  1. for循环没有完成第一次迭代。
  2. 我的代码最初没有完成if else if语句。
  3. 我仔细检查了我的括号,然后我更改了if else语句,以便它们起作用,至少完成了它的工作。

    运行我的代码之后,我意识到它只通过for循环一次,当退出时,代码完全冻结,之后什么也没发生。所以它没有完成一次迭代。

    我真的很感激任何答案,因为我完全无能为力。 谢谢。

    public static void Level1()
        {
            //initialize the potatoes
            planet = new WorldOPotatos(new Vector(5, 0, 0), new Vector(0, 0, 0), 5E12);
            string text = "";
            double testedChi = 0;
            double testedAngle = 0;
            double minChi = 10000;
            double minAngle = 0;
            double angleIncrement = 0.1;
    
            //optimize angle
            // angle must be between 0 and pi/2
            for (double angle = 0; angle <= Math.PI/2.0; angle += angleIncrement)
            {
                //define potato
                potat = new Potato(
                    new Vector(0, 0, 0),
                    new Vector(10 * Math.Cos(angle), 10 * Math.Sin(angle), 0),
                    new Vector(0, 0, 0));
    
                // shoot potato and put the needed values in here
                Vector initialVelocity = potat.Velocity;
                testedChi = ShootPotato1(potat, planet);
                testedAngle = angle;
                text += (initialVelocity.ToString()) + "\t" + (testedChi.ToString()) + "\n";
    
                //test to see if we should change the increments
                if (testedChi == minChi)
                {
                    break;
                }
                else
                {
                    if (testedChi > minChi)
                    {
                        angle -= angleIncrement;
                        angleIncrement = 0.001;
                    }
                    else
                    {
                        minChi = testedChi;
                        minAngle = testedAngle;
                    }
                    Console.WriteLine(":O");
                }
                Console.WriteLine(":OO");
                // loop gets here, but that's where it stops.
            }
            Console.WriteLine("Nothing is working");
    
            PrintValues(fileName1, minChi.ToString() + "\t" + minAngle.ToString());
        }
    

    我修复的一个问题是&#34;无法获得本地或参数的值,因为它在此指令指针处不可用,可能是因为它已被优化掉了,&#34;所以我按照最高回应的指示。但是,我仍然遇到同样的问题。

0 个答案:

没有答案