对于循环空语句问题

时间:2017-03-06 11:55:03

标签: c# for-loop

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            double Qd, Qe, Hd, He, Hplus, B, Leffd, Leffe, Ln, np, bp, Ka, Kp, Cd, Ce, Qhesapd, Qhesape, farkd, farke;

            Qd = 60.30;
            Qe = 120;
            Hd = 0.0001;
            He = 0.0001;
            Hplus = 1;
            B = 8.2;
            np = 1;
            bp = 1.2;
            Ka = 0.1;
            Kp = 0.01;
            Ln = B - np * bp;
            Leffd = Ln - (Ka + Kp * np) * 2 * Hd;
            Leffe = Ln - (Ka + Kp * np) * 2 * He;
            Cd = 0.3849 * (1 + (4) / (14));
            Ce = 0.3849 * (1 + (4 * Hplus) / (9 + 5 * Hplus));
            Qhesapd = Cd * Leffd * Math.Sqrt(Math.Pow(Hd, 3) * 19.62);
            Qhesape = Ce * Leffe * Math.Sqrt(Math.Pow(He, 3) * 19.62);
            farkd = Qhesapd - Qd;
            farke = Qhesape - Qe;

        for (Hd = 0.0001; farkd < 0.0001; Hd+=0.0001)
            {
                Cd = 0.49487;
                Leffd = Ln - (Ka + Kp * np) * 2 * Hd;
                Qhesapd = Cd * Leffd * Math.Sqrt(Math.Pow(Hd, 3) * 19.62);
                farkd = Qhesapd - Qd;
            }
            label1.Text = Math.Round(Cd,5).ToString();
            label2.Text = Math.Round(Leffd, 4).ToString();
            label3.Text = Math.Round(Hd, 4).ToString();

        //Where things get weird//

        for (He = 0.0001; farke < 0.0001; He += 0.0001);
            {
                Hplus = He / Hd;
                Ce = 0.3849 * (1 + (4 * Hplus) / (9 + 5 * Hplus));
                Leffe = Ln - (Ka + Kp * np) * 2 * He;
                Qhesape = Ce * Leffe * Math.Sqrt(Math.Pow(He, 3) * 19.62);
                farke = Qhesape - Qe;
            }
            label4.Text = Math.Round(Ce, 5).ToString();
            label5.Text = Math.Round(Leffe, 4).ToString();
            label6.Text = Math.Round(He, 4).ToString();


        }
    }

2 for循环之间有一条注释行。如果我没有添加第二个for循环,代码可以正常工作。在第一个循环中,我获得了一个'Hd'值,我在第二个循环中使用了这个值,是不是错了?顺便说一句,有关于错误列表中第二个循环的警告,其中显示“可能错误的空语句”。

1 个答案:

答案 0 :(得分:4)

删除行尾的分号!这是一个典型的错误,你将来应该小心......它使for循环什么都不做

for (He = 0.0001; farke < 0.0001; He += 0.0001);