- Joined
- Jan 23, 2015
- Messages
- 1,677
- Likes
- 1,442
- Degree
- 4
Ok I'm pretty confused right now but I have a question about the following while loop:
How come the code works but the variable is defined inside the loop? The while loop condition variable was not yet defined (in the first line of code) so surely that should throw an error?
Wouldn't I have to define the input variable outside and before the while loop?
Code:
while(input !== "stop"){
var input = prompt("Input something");
}
How come the code works but the variable is defined inside the loop? The while loop condition variable was not yet defined (in the first line of code) so surely that should throw an error?
Wouldn't I have to define the input variable outside and before the while loop?