转换循环(Java初学者问题) [英] Converting loops (Java Beginner question)

查看:57
本文介绍了转换循环(Java初学者问题)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在循环之间进行转换是否总是这样?还是有些情况不是呢?在解决Exam这样的问题时最快的检查方法是什么?

Does Converting between loops always works like this? or there is some situation that it does not? and what is the fastest way to check while I'm solving a question like this in Exam?

对于循环:

 for(xx;yy;zz)
    { 
       aa
    }

循环时

    xx
    while(yy)
    {
      aa
      zz
    }

执行时间:

      xx
      do
      { 
        aa
        zz
      }
    while(yy)

推荐答案

您有几个错误.特别是do-while循环是不正确的,因为它总是执行至少一个迭代,而forwhile循环则不是这种情况.

You have couple of mistakes. Especially do-while loop is incorrect since it always executes at least one iteration, which is not the case for for and while loops.

for(x(); y(); z())
{ 
   a();
}

x();
while(y())
{
  a();
  z();
}

x();
if(y())
{
  do
  { 
    a();
    z();
  } while(y())
}

这篇关于转换循环(Java初学者问题)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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