简体   繁体   English

从while循环退出

[英]exit from while loop

Here i am having function like this. 在这里,我有这样的功能。 problem i am facing while changing Set parameter section. 更改“设置参数”部分时遇到的问题。 first: i could not able to change Set_parameter Window Second: Since in my loop i am saying if none key pressed display clock.because of that when i enter into Section menu it directly bounce back to Main displaying clock. 第一:我无法更改Set_parameter窗口第二:由于在循环中我说是否没有按键按下显示时钟,因此当我进入``分区''菜单时它会直接跳回主显示时钟。 Is there any way, where i can stay menu section unless Exit/LEFT key pressed 有没有办法,除非按退出/左键,否则我可以停留在菜单部分

This main function where i am calling my LCD_call Function 我正在调用LCD_call函数的主要功能

 void loop()
    {
     int button;
     while(( button = read_LCD_buttons()) != btnNONE)
     {
     lcd_call();digitalClockDisplay();
     }
    }

LCD_call being called here. LCD_call在这里被调用。 LCD_call LCD_call

break command should break/exit the loop. break命令应中断/退出循环。 It could be that the if condition is not coming out to be true, for any input case. 对于任何输入情况, if条件可能都不成立。

Try debugging your code by placing a break point inside if . 尝试通过在if放置一个断点来调试代码。

if(button==btnSELECT) { break; // place your breakpoint here. }

and check if your code satifies the if condition for any possible input. 并检查您的代码if满足任何可能输入的if条件。

This should work : 这应该工作:

void lcd_call()
{
    while ( (button = read_LCD_buttons()) != btnSELECT)
    {
        DS_Counter=Display_selection();

        switch (DS_Counter)
        {
            case 1:
                lcd.setCursor(0,0);
                digitalClockDisplay();
                timedBeep(shortBeep,1);
                break;
            case 2:
                lcd.setCursor(0,0);
                Display_angle();
                timedBeep(shortBeep,1);
                break;
            case 3:
                lcd.setCursor(0,0);
                Display_coordinate();
                timedBeep(shortBeep,1);
                break;
            case 4:
                lcd.setCursor(0,0);
                Display_Wind();
                timedBeep(shortBeep,1);
                break;
            case 5:
                break;
        }
    }
}

You have already given a condition in While loop. 您已经在While循环中指定了条件。 As soon as the condition is false, it will break the while loop 条件为假时,它将打破while循环

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM