For循环是否总是至少执行一次? [英] Is a For Loop always executed at least once?

查看:2357
本文介绍了For循环是否总是至少执行一次?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据我的老师,即使不满足条件,for循环也至少执行一次.

According to my teacher, a for-loop always executes at least once, even if the condition is not met.

示例(就像我从C ++知道的那样):

Example (like I know it from C++):

for (int i=6; i <=5; i++) {
    //irrelevant for this question
}

根据她的说法,此循环将至少执行一次,但不会执行一次,还是我遗漏了什么? 是否有任何情况,无论使用哪种语言,都将在哪里执行一次? 要事先消除这种想法:是的,它是关于for循环的,而不是do-while-loops.

According to her, this loop would execute at least once, yet it does not, or am I missing something? Is there any case, no matter what language, where this would execute once? To eliminate the thought in advance: yes, it was about for loops, not do-while-loops.

修改:

感谢所有这些快速解答,我想这个案例已经结案了.晚上/晚上过得愉快.

Thanks for all those quick answers, I guess this case is already closed. Have a nice day/night.

推荐答案

您可以说一个for循环总是至少被 评估 一次.

You could say a for-loop is always evaluated at least once.

但是,如果不满足for循环的条件,它将永远不会执行.

But if a for-loop's condition is not met, its block will never execute.

因为您没有询问其他循环,所以我不会解决这些循环.

Because you didn't ask about other loops, I won't address those.

这篇关于For循环是否总是至少执行一次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆