如何循环退出? [英] How to While Loop Exit?

查看:88
本文介绍了如何循环退出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





请帮助我,如何循环退出。我指示了地方,,,

Hi,

Kindly help me, How to While loop Exit . I indicated place,,,

using (XmlReader reader = XmlReader.Create(new StringReader(recievedXML), xrs))
    {

        while (reader.Read())
        {
            if (reader.IsStartElement())
            {
                switch (reader.Name)
                {
                    case "start":
                        String time = DateTime.Now.TimeOfDay.ToString();
                        StartTimeTextBox.Text = time.Substring(0, time.Length-8);
                        break;
                     case "vol":

                        if (reader.Read())
                        {
                            volumeTextBox.Text = reader.Value;
                            csvData.Append(reader.Value + ";");
                        }
                        else
                        {
                            MessageBox.Show("Data Not Read");

/// ====================================> I want to whlie Loop exit here     <===============

                        }

                        String time1 = DateTime.Now.TimeOfDay.ToString();

                        EndTimeTextBox.Text = time1.Substring(0, time1.Length-8);

                        break;

                    case "hct":

                        if (reader.Read())

                        {

                            HctTextBox.Text = reader.Value;

                            csvData.Append(reader.Value + ";");

                        }

                        break;

                    case "joule":

                        if (reader.Read())

                        {

                            EnergyTextBox.Text = "00"+reader.Value;

                            csvData.Append("00"+reader.Value + ";");

                        }

                        break;

                    /*case "jouleend":

                        if (reader.Read())

                        {

                            jouleendTextBox.Text = reader.Value;

                            csvData.Append("jouleend," + reader.Value + "\n");

                        }

                        break;*/

                    case "complete":

                        if (reader.Read())

                        {

                            ProcedureCompletedTextBox.Text = "OK";

                            csvData.Append("OK" + ";");

                        }

                        break;

                    case "runtime":

                        if (reader.Read())

                        {

                            TotalTimeTextBox.Text = reader.Value;

                            csvData.Append(reader.Value + ";");

                        }

                        break;

                    case "pausetime":

                        if (reader.Read())

                        {

                            PauseTextBox.Text = reader.Value;

                            csvData.Append(reader.Value + ";");

                        }

                        break;

                    case "nrpause":

                        if (reader.Read())

                        {

                            NoOfPauseTextBox.Text = reader.Value;

                            csvData.Append(reader.Value + ";");

                        }

                        break;

                    case "temperature":

                        if (reader.Read())

                        {

                            temperatureTextBox.Text = "00"+reader.Value;

                            csvData.Append("00"+reader.Value + ";");

                        }

                        break;

                }

            }

        }

    }

}

catch (Exception e)

{

    String fileName = Path.GetPathRoot(Environment.SystemDirectory) + "\\MED_DATA\\exception_" + DateTime.Now.ToString("ddMMyyyyhhmmss") + ".txt";

    File.WriteAllText(fileName, e.Message + "\n" + e.StackTrace + "\n" + e.Source + "\n" + e.InnerException + "\n" + e.ToString());

}







[Edit member=\"Tadit\"]

Added pre tags.

[/Edit]

推荐答案

Normally you’d break out of it. But what I’d be inclined to do here is put the while loop in its own method, and use a return to get out of that.



An alternative would be to create a Boolean, and set it where you want to exit. Use the Boolean in an ’and’ condition in the while statement.
Normally you'd break out of it. But what I'd be inclined to do here is put the while loop in its own method, and use a return to get out of that.

An alternative would be to create a Boolean, and set it where you want to exit. Use the Boolean in an 'and' condition in the while statement.


这篇关于如何循环退出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆