cny1947
08-31-2006, 11:21 AM
I need to write a loop that adds numbers from users...but need to offer a chance to get out of the program with a break statement. Any ideas?
|
||||
Loops and break statements.cny1947 08-31-2006, 11:21 AM I need to write a loop that adds numbers from users...but need to offer a chance to get out of the program with a break statement. Any ideas? Kor 08-31-2006, 11:53 AM You said it: break for(........){ if(condition){break} } But you may also use a while loop (in your case): <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta http-equiv="Content-Style-Type" content="text/css"> <meta http-equiv="Content-Script-Type" content="text/javascript"> <script type="text/javascript"> onload = function(){ var conf=true; var num=''; while(conf){ num=num+prompt('Enter a number','')+' | ' var conf=confirm('Continue!') } document.getElementById('mydiv').innerHTML=num } </script> </head> <body> <div id="mydiv"></div> </body> </html> |
| |||
EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum