What is the purpose of a do-while loop?

前端 未结 5 2144
说谎
说谎 2021-01-17 08:59

I know what do does, and how it cooperates with the while loop, but won\'t a while loop code be the same, whether or not the do is there?

5条回答
  •  情书的邮戳
    2021-01-17 09:52

    if you write the "loop" like so (without the do as in your question):

    int i=0;
    {
        System.out.println(i++);
    }while(i<10);
    

    it will just print out 0 (nothing more), and not loop 10 times.. so no, the loop won't be the same if the do isnt there.

提交回复
热议问题