Javascript 提示不断出现

Javascript Prompt keeps appearing

询问 "Enter number of Ounces" 的提示不断重复出现,即使在提示中输入一个值之后...我该怎么做才能删除循环提示...我只需要它出现一次.

<html>
    <body>
        <script type="text/javascript">
            //
            // ******************************
            // Program: LAB3ALT.htm
            // Created by: Tanner DiBella 
            // Date: February 10, 2015
            // Function: Convert Ounces to Pounds
            // *******************************
            //
            /*
            The Ounce to Pounds formula: 1 ounce = 0.0625 pounds
            */

            var i=0;

            while (i<=0) {
                var ounces = prompt("Enter number of Ounces" , "1"); 

                if (ounces==null) { /* Test for cancel */
                    i="1";
                }
                else {
                    var pounds= ounces * 0.0625; /* Compute number of pounds */
                    document.write("<BR>","Ounces : ",ounces);
                    document.write("<BR>","Pounds : ",pounds);
                    document.write("<BR>");
                }
            }
        </script>
    </body>
</html> 

else里面,需要设置i>0。这样就可以了。

虽然,这里很混乱。你想让我做什么?一个更简单的版本是,

while(true){   //It will repeat indefinitely unlesss you break out of it
    var ounces = prompt("Enter number of Ounces: " , "0");
    if (ounces != null) { //Checks if user cancelled, if yes, it reappears
        var pounds= ounces * 0.0625; /* Compute number of pounds */
        document.write("<BR>","Ounces : ",ounces);
        document.write("<BR>","Pounds : ",pounds);
        document.write("<BR>");
        break;  //when criteria is met, you break out of the loop
    }
}