-4

I came across this piece of code but I'm not familiar with this while loop syntax.

while(i < j){
    while(distance(arr[++i]) < distance(p));
    while(distance(arr[--j]) > distance(p));
    if(i < j){
        swap(arr, i, j);
    }
}

I've never seen a while loop without braces that end in semicolons. What do they mean?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197

1 Answers1

-1

while(cond);

is the same as

while(cond) {}

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Chr L
  • 89
  • 4
  • 1
    I have removed your final comment. It works because a while is followed by a statement or a block, and just `;` is considered a valid statement in Java (and empty statement). – Mark Rotteveel Aug 03 '23 at 12:19
  • Regardless that your answer is correct or not, you are encouraged to edit it to explain why this is the best answer to the question. – Tom Solid Aug 04 '23 at 11:43