|
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>
|
|
|
Copyright © 1996-2008 irt.org, All Rights Reserved.