What do two semicolons mean in Java for loop?

前端 未结 5 1120
渐次进展
渐次进展 2020-12-17 07:51

I was looking inside the AtomicInteger Class and I came across the following method:

/**
 * Atomically increments by one the current value.
 *
          


        
相关标签:
5条回答
  • 2020-12-17 08:22

    It's the same thing as

    while(true) {
        //do something
    }
    

    ...just a little bit less clear.
    Notice that the loop will exit if compareAndSet(current, next) will evaluate as true.

    0 讨论(0)
  • 2020-12-17 08:23

    That is a for ever loop. it is just a loop with no defined conditions to break out.

    0 讨论(0)
  • 2020-12-17 08:26

    It's an infinite loop, like while(true).

    0 讨论(0)
  • 2020-12-17 08:27

    It's just another variation of an infinite loop, just as while(true){} is.

    0 讨论(0)
  • 2020-12-17 08:31

    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

    0 讨论(0)
提交回复
热议问题