Closed
Bug 213989
Opened 21 years ago
Closed 21 years ago
Problem with while loop execution.
Categories
(Core :: JavaScript Engine, defect)
Tracking
()
VERIFIED
DUPLICATE
of bug 114461
People
(Reporter: everett, Assigned: rogerl)
Details
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624
Here is the web page. It has a simple while loop which I have been
demonstrating to my class:
<html>
<head>
<script language='Javascript1.3' src = ''></script>
<script language='Javascript1.3'>
function doloop(a)
{
var ii = 0
while ( ii < a)
{
document.write( "Loop no " + ii + "<br />" )
ii++
if ( ii > 1000) { break }
}
}
</script>
<link rel='stylesheet' type='text/css' href='' />
<style type='text/css'>
</style>
<title></title>
</head>
<body>
<h1>While Loops</h1>
<form>
<a href='Javascript:doloop(6)'>Do a loop</a>
</form>
</body>
<script language='Javascript1.3'>
</script>
</html>
(1) While this will execute correctly and print the correct no of lines, the
browser icon continues to cycle, suggesting that the page is not finished.
(2) If var is removed from the line 'var ii = 0', the loop will not execute at
all and you get the single line of output, 'Loop no 0'. Again, the browser
appears to cycle until the stop icon is clicked. Venkman says that ii is not
defined. Although using var is more proper, it has never been mandatory in
Javascript, especially if the variable is initialized, as this one has been; it
just becomes global.
I have tried this page in Opera 7.1 and IE 6, both of which have less capable
parsers than Gecko's and the pages work perfectly.
Mona Everett
Reproducible: Always
Steps to Reproduce:
1. Just run this web page and click on the link
2.
3.
Actual Results:
As stated in details
Expected Results:
Mozilla should have written the line, 'Loop no ' + ii, a number of times and quit.
Comment 1•21 years ago
|
||
> (1) While this will execute correctly and print the correct no of lines, the
> browser icon continues to cycle, suggesting that the page is not finished.
The first call to document.write() on a document that is no longer loading calls
document.open() and the page is not finished until document.close() is called.
See bug 81980 for some discussion on that.
> (2) If var is removed from the line 'var ii = 0'
The problem then is that 'ii' is then defined on the global scope; when the
document.open() call happens the global scope is cleared. This is covered by
bug 114461.
Randomly choosing one of those to mark duplicate of (the one that I think is a
real bug, really ;) ).
*** This bug has been marked as a duplicate of 114461 ***
Status: UNCONFIRMED → RESOLVED
Closed: 21 years ago
Resolution: --- → DUPLICATE
Comment 2•21 years ago
|
||
Marking Verified.
Mona: thanks for this report; you have been cc'ed on bug 114461
so you can follow progress on that -
One other point: we are currently up to JavaScript 1.5 at this point.
Unless you want to use some specific trait of JavaScript 1.3, it is
not advisable to hard-code the version as you have done:
<script language='Javascript1.3'>
Instead, do:
<script language='JavaScript'>
That will ensure the browser uses the latest available version of JS.
Status: RESOLVED → VERIFIED
You need to log in
before you can comment on or make changes to this bug.
Description
•