user1448458
user1448458

Reputation:

Java for (;;) loop

I was looking at the AtomicBoolean class source and found interesting declaration of the for loop like this:

for (;;) { 
   //Something
}

What does this loop?

Upvotes: 3

Views: 366

Answers (5)

Addict
Addict

Reputation: 823

for (;;) { 
   //Something
}

This is infinite loop.

Upvotes: 0

halex
halex

Reputation: 16403

This is an endless loop that will not stop execution if you have no break statement inside. It's the same as while(true).

Upvotes: 1

Darin Dimitrov
Darin Dimitrov

Reputation: 1039050

What does this loop?

It loops indefinitely. It's like:

while (true) {

}

Upvotes: 0

user1898811
user1898811

Reputation:

This is shorthand for an infinite loop. It will continue until a break statement causes execution to escape the loop.

Upvotes: 2

Paulius Matulionis
Paulius Matulionis

Reputation: 23413

It is an infinite loop. The same you can do with:

while (true) {
  //Loops forever.
}

Take a look at the docs.

Upvotes: 10

Related Questions