Converting loops (Java Beginner question)

前端 未结 5 434
独厮守ぢ
独厮守ぢ 2020-12-20 06:45

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 th

5条回答
  •  醉酒成梦
    2020-12-20 07:20

    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())
    }
    

提交回复
热议问题