while 和 do while 循环语句格式及用法
生活随笔
收集整理的這篇文章主要介紹了
while 和 do while 循环语句格式及用法
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
class? ifDemo
{
?? ?public static void main(String[] args)
?? ?{
?? ??? ?/*
?? ??? ?循環語句介紹:
?? ??? ???? while 循環語句
?? ??? ??? ?while(條件表達式)
?? ??? ??? ?{
?? ??? ??? ??? ?執行語句;
?? ??? ??? ?}
?? ??? ??? ?do while 循環語句
?? ??? ??? ?do
?? ??? ??? ?{
?? ??? ??? ??? ?執行語句
?? ??? ??? ?}
?? ??? ??? ?while(條件表達式)
?? ??? ?*/
?? ??? ?int i=1;
?? ??? ?while(i<5)
?? ??? ?{
?? ??? ??? ?System.out.println("hello word");
?? ??? ??? ?i++;
?? ??? ?}
?? ??? ?
?? ??? ?int x=1;
?? ??? ?do
?? ??? ?{
?? ??? ??? ?System.out.println(x);
?? ??? ??? ?x++;
?? ??? ?}
?? ??? ?while (x<=5);
?? ?}
}
{
?? ?public static void main(String[] args)
?? ?{
?? ??? ?/*
?? ??? ?循環語句介紹:
?? ??? ???? while 循環語句
?? ??? ??? ?while(條件表達式)
?? ??? ??? ?{
?? ??? ??? ??? ?執行語句;
?? ??? ??? ?}
?? ??? ??? ?do while 循環語句
?? ??? ??? ?do
?? ??? ??? ?{
?? ??? ??? ??? ?執行語句
?? ??? ??? ?}
?? ??? ??? ?while(條件表達式)
?? ??? ?*/
?? ??? ?int i=1;
?? ??? ?while(i<5)
?? ??? ?{
?? ??? ??? ?System.out.println("hello word");
?? ??? ??? ?i++;
?? ??? ?}
?? ??? ?
?? ??? ?int x=1;
?? ??? ?do
?? ??? ?{
?? ??? ??? ?System.out.println(x);
?? ??? ??? ?x++;
?? ??? ?}
?? ??? ?while (x<=5);
?? ?}
}
總結
以上是生活随笔為你收集整理的while 和 do while 循环语句格式及用法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 流程控制之循环语句
- 下一篇: Arduino基础知识复习12.18