title: How do I convert this if statement to a while or a do-while loop?
body: <p>I am using Javascript and was wondering how to convert this to a loop. So an if statement only allows one pass. I want to change it to a loop so that that if I keep entering a number higher than 8 my program will keep re-running the prompt. In an if statement, after the wrong first try, my program displays: 
  The value entered is too large 
  Value of n = 9
  Value of A[9] = undefined 
  I want to do it so that it keeps making you run the program until you enter a number 1-8 because thats how many var A I have.
  Here is the coding:</p>
  
  <pre><code>var A = [1,12,23,34,45,56,67,78], maxlen = A.length;
  var n = prompt("What element number do u want to access");
  if (n &gt;= 0 &amp;&amp; n &lt; A.length)
      {
      document.write("Value of n = ", n, "&lt;br \&gt;", "Value of A[", n, "] = ", A[n]);
      }
  else {
      document.write("The value entered is too large &lt;br \&gt;");
      n = prompt("Max length is "+maxlen+"\n What element number do you want to access");
      document.write("Value of n = ", n, "&lt;br \&gt;", "Value of A[", n, "] = ", A[n]);
  </code></pre>