Look at the Java and Delphi source codes below. Which one will compile, and which one will run in an infinite loop? (click on ‘more…’ to see the answer)

Java:

void loop() {
 while (true) {
  try {
   return;
  } finally {
   continue;
  }
 }
}

Delphi:

procedure Loop;
begin
 while True do
 try
  Exit;
 finally
  Continue;
 end;
end;

Answer: Only the Java code compiles, and runs in an infinite loop. The Delphi compiler will stop with the error message “Cannot BREAK, CONTINUE or EXIT out of a FINALLY clause”.