在Java中,两个分号意味着什么? [英] What do two semicolons mean in Java for loop?
本文介绍了在Java中,两个分号意味着什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
code> / **
*原子上增加一个当前值。
*
* @返回上一个值
* /
public final int getAndIncrement(){
for(;;){
int current = get ();
int next = current + 1;
if(compareAndSet(current,next))
return current;
$ b有人可以解释
(;;)
是指?
解决方案当(true)时,它相当于
。
没有设置它们,使得它成为一个无限循环。
for循环有三个元素:
- 初始值设定项
- 条件(或终止表达式)
- 增量表达式
code> for(;;)
参考: for语句
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; } }
Can someone explain what
for(;;)
means?解决方案It is equivalent to
while(true)
.A for-loop has three elements:
- initializer
- condition (or termination expression)
- increment expression
for(;;)
is not setting any of them, making it an endless loop.Reference: The for statement
这篇关于在Java中,两个分号意味着什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文