Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

Q1613 How can I exit a function in Javascript?

irt.org | Knowledge Base | JavaScript | General | Q1613 [ previous next ]

Q1613 How can I exit a function in Javascript?

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>

Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.