text 无限循环2通常用于检查输入验证

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了text 无限循环2通常用于检查输入验证相关的知识,希望对你有一定的参考价值。

do
{

}
while (boolean-expression); //beware there is ";" in the end

There is actually another way to realize this using the first type of loop, like this:

 // Expect notes from user until EOF
    while (true)
    {
        // Expect note
        string line = get_string("");

        // Check for EOF
        if (line == NULL)
        {
            break;
        }

        // Check if line is rest
        if (is_rest(line))
        {
            rest_write(s, 1);
        }
        else
        {
            // Parse line into note and duration
            string note = strtok(line, "@");
            string fraction = strtok(NULL, "@");

            // Write note to song
            note_write(s, frequency(note), duration(fraction));
        }
    }
    
    So we start by writing while(true), so it will always be true, and we set a "break" inside it. So as the above code, the input string will also run first at least once, then check if it's an empty string, if it is then will break out of the loop. If not then go further down. It will continue looping until the input is an empty string, then it will break out of the loop.
    
    

以上是关于text 无限循环2通常用于检查输入验证的主要内容,如果未能解决你的问题,请参考以下文章

无限循环计算阶乘问题

PassportJs 身份验证无限循环和执行(默认)查询

检查密码,验证,然后再次循环

appium 检查器中的无限循环

检查空无限循环中的选项与做一些无限循环

无限循环数据库检查