20130327java基础学习笔记-循环结构while及do while

1.循环结构:
代表语句:while,do while,for;
I.while循环:
class WhileDemo
{
    public static void main(String[] args)
    {
        /*
        while(条件表达式)
        {
            执行语句;
        }
        */
        int x = 1;
        while(x<3)
        {
            System.out.println("x="+x);
            x++;
        }//这个大括号内容叫做循环体;
    }
}
II.do while循环:
class DoWhileDemo
{
    public static void main(String[] args)
    {
        /*
        do while语句格式:
        do
        {
            执行语句;
        }while(条件表达式);
        */
        int x = 1;
        do
        {
            System.out.println("x="+x);
            x++;
        }while(x<1);
        /*
        do while特点:是条件无论是否满足,循环体至少执行一次;
        */
        int y = 1;
        while(y<1)
        {
            System.out.println("y="+y);
        }
    }
}

posted @ 2013-03-27 10:01  馨云  阅读(140)  评论(0编辑  收藏  举报