stuck with Javascript infinite while loop -


my apologies n00b question, i've tried looking through infinite loop related issues they're way more complex:

var replay = 1; while (replay = 1) { replay = prompt("yes(1) or no(0) ?"); } 

how come infinite loop?

i thought while loop continue iterating while replay variable has value of 1.

however doesn't stop when user input 0, or else matter.

thanks in advance of input!

you assigning not checking in (replay = 1)

you need double equal signs ==, or better yet triple equal signs === check equality in types of operands.

besides, code can changed (preview: http://jsfiddle.net/nabil_kadimi/rfda5/):

var replay; while ((replay = window.prompt("yes(1) or no(0) ?")) === '1') {   /* player wants replay */; } 

or better (preview: http://jsfiddle.net/nabil_kadimi/pdv4m/):

var replay; while (replay = window.confirm("replay?")) {   /* player wants replay */; } 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -