How to return control of flow to a for loop?

假如想象 提交于 2019-12-24 22:09:16

问题


I'm trying to code a loop to re execute a block of code 3 times. At the moment the code starts and executes once but doesn't repeat as intended with using the for loop.

I've set a break point on the for loop and it only goes through the loop once.

    private async void startBtn_Tap(object sender, System.Windows.Input.GestureEventArgs e)
    {
        int i;
        int roundMax = 3;

         for (i = 1; i <= roundMax; i++)
         {
                //delay stop watch start to allow time to get ready.
                TimeSpan time = TimeSpan.FromSeconds(1);
                await System.Threading.Tasks.Task.Delay(time);


                //set text box editing to false to prevent illegal input.
                wrkTbx.IsEnabled = false;
                restTbx.IsEnabled = false;
                roundSlider.IsEnabled = false;
                roundsTbx.IsEnabled = false;

                StopGoCvs.Background = new SolidColorBrush(Colors.Green);
                //startSoundElmt.Play();
                // set up the timer
                myTimer = new DispatcherTimer();
                myTimer.Interval = new TimeSpan(0, 0, 0, 0, 1);

                myTimer.Tick += myTimer_Tick;

                // start both timers
                myTimer.Start();
                myStopwatch.Start();



        }

    }

回答1:


this is a logical issue, and I suspect it exits the for loop at some point, Assumming you're using Visual Studio, I would use Breakpoints at every steps and run the program to see where it fails, you may be missing a return or else somewhere



来源:https://stackoverflow.com/questions/26384491/how-to-return-control-of-flow-to-a-for-loop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!