For loop won't end. Don't know why -


i'm writing loop project prompts user input number , keeps prompting, continually adding numbers up. when string introduced, loop should stop. i've done while loop, project states must loop also. problem prompt keeps running when 'a = false'. explain javascript's thinking process? want understand why keeps running through loop though condition isn't met. thank you

 var addsequence2 = function() {          var total = 0;         var a;          (; = true; ) {             var input = prompt("your current score " +total+ "\n" + "next number...");              if (!isnan(input)) {                 = true;                 total = +total + +input;             }             else if (isnan(input)) {                 = false;                 document.write("your total " + total);             }         }  }; 

there difference between a = true , a == true.

your for-loop asking "can set 'a' true?", answer yes, , loop continues.

change condition a == true (thus asking "is value of 'a' true?")


to elaborate, in programming languages, distinguish between assignment ("make 'x' 4") , testing equality ("is 'x' 4?"). convention (at least in languages derive syntax c), use '=' assign/set value, , '==' test.

if i'm understanding specification correctly (no guarantee), happens here condition condenses follows:

  1. is (a = true) true?
  2. complete bracket: set true
  3. is (a) true? (we set true, must be!)

Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

qt - How to embed QML toolbar and menubar into QMainWindow -