嵌套for / if循环和语句

时间:2017-08-25 09:33:42

标签: c# loops for-loop if-statement nested

if (first statement) 
{
    for (first loop) 
    {
        if (second statement) 
        {
            for (second loop) 
            {       
                if (third statement) 
                {
                    Do something;
                }
            } 
        }
    }
}

问题是,如果第三个陈述是假的,它会进入第一个循环还是第二个循环? C#

3 个答案:

答案 0 :(得分:1)

如果第三个if为false,它将完成它所属的for循环,之后它将完成第二个循环,直到if为true或刚刚结束并返回第一个

答案 1 :(得分:0)

如果第三个语句为false,则只需继续第二个for循环,因为它只是此for循环的一次迭代。您将保持不变,直到不再验证让您进入for循环的条件。然后,您将使用相同的推理返回到第一个 questionObj.JS.forEach(function(question, questionNumber) { $('body').append('<div class="quiz-container" id="question_'+questionNumber+'">'+question.question+'</div>') for(var letter in question.options) { $('#question_'+questionNumber).append('<li>'+question.options[letter]+'</li>') } }) 循环。

答案 2 :(得分:0)

if (first statement) {
for (first loop) {
if (second statement) {
for (second loop) {
if (third statement) { // if false, will still do what comes after here
Do something;
}
if{ 4th statement // will still do this.
}
} 
}
}
}

仍然会进行循环

相关问题