简体   繁体   English

按时停止while功能

[英]Stop the while function on time

I need to create a string up to the point when I get a * character and I would like to do it without having to double the condition (c!='*') . 我需要创建一个字符串,直到获得一个*字符,并且我希望这样做而不必将条件(c!='*')加倍。 I tried while(){...} and do {...} while() but the * is still added. 我尝试了while(){...}do {...} while()但*仍被添加。

Here is a piece of code: 这是一段代码:

while (c!='*')
            {
                c=dec.checkChar(dec.extractCode(t, d));
                d=d.shiftRight(7);
                if (c!='*')decoded+=c;
            } 
while(true){
            c=dec.checkChar(dec.extractCode(t, d));
            if(c=='*'){
                 break;
              }
            d=d.shiftRight(7);
            decoded+=c;
            } 

Don't change c immediately after checking it in the outer loop. 在外部循环中检查后不要立即更改c Instead, restructure you logic to process the c you just checked wasn't an exit condition, and the make updating the c the last thing you do. 取而代之的是,重组您的逻辑以处理刚刚检查的c不是退出条件,而使c更新成为您要做的最后一件事。

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

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