Java for 循环中的两个分号是什么意思? [英] What do two semicolons mean in Java for loop?
本文介绍了Java for 循环中的两个分号是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我查看了 AtomicInteger
类的内部,发现了以下方法:
I was looking inside the AtomicInteger
Class and I came across the following method:
/**
* Atomically increments by one the current value.
*
* @return the previous value
*/
public final int getAndIncrement() {
for (;;) {
int current = get();
int next = current + 1;
if (compareAndSet(current, next))
return current;
}
}
有人能解释一下 for(;;)
是什么意思吗?
Can someone explain what for(;;)
means?
推荐答案
等价于 while(true)
.
for 循环包含三个元素:
A for-loop has three elements:
- 初始化器
- 条件(或终止表达式)
- 增量表达式
for(;;)
没有设置它们中的任何一个,使其成为无限循环.
for(;;)
is not setting any of them, making it an endless loop.
参考:for 语句
这篇关于Java for 循环中的两个分号是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文