for & while &迭代器

for (int i = 0; i < 10; i++)
{
System.out.println("hello");

}

int a=100;
for (;a<110;a++)
{
System.out.println("hello");
}

for(;;) //无限循环 相当于while(true)
{
System.out.println("A");
}

//多变量
int count=5;
for(int i=0,j=0;i<count;i++,j+=2)
{
System.out.println("i="+i+"j="+j);
}

 

while可以一次不执行;

do{}while(循环条件)  至少执行一次;  

  int count=5;
   do{
           System.out.println("do while");
           count--;
       }while(count>1);


     while (count>1)
        {
            count--;
            System.out.println("aaa");
        }
View Code
continue与break后,在方法内
return后,跳出方法
 
迭代器
 private static HashMap<String, ServerConnectClientThread> hm = new HashMap<>();

   Iterator<String> iterator = hm.keySet().iterator();
        String onlineUserList = "";
        while (iterator.hasNext()) {
            onlineUserList += iterator.next().toString() + " ";
        }
View Code

 

posted @ 2022-03-02 15:06  磕伴  阅读(32)  评论(0)    收藏  举报