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 @   磕伴  阅读(27)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 字符编码:从基础到乱码解决
· 提示词工程——AI应用必不可少的技术
点击右上角即可分享
微信分享提示