You are here: irt.org | FAQ | JavaScript | General | Q1613 [ previous next ]
By using the return statement. For example, the following function exits as soon as the counter has reached 100:
<html> <head> <title>return statement</title> </head> <body> <script language="JavaScript"><!-- function count() { for (var counter=0;;counter++) { // an infinite loop document.write(counter + '<br>'); if (counter == 100) return; } } count(); //--></script> </body> </html>