I'm trying to make it so the program repeatedly accepts input and repeats it back until "exit" is inputted. Right now the loop doesn't run, and I don't know why since the exit variable is set to false. Here's my code:
var read = require("read");
var exit = false;
function OutsideLoop (exit) {
while(exit === false){
read({prompt: "> "}, function (err, result) {
console.log("");
console.log(result);
console.log("Type in more input or type 'exit' to close the program.");
if(result === "exit"){
exit = true;};
});
};
};
OutsideLoop();
Thanks for the help guys. I have a similar loop working using if/then instead of while, so I rewrote this one along the same lines.
if(!exit)exit = false;in yourOutsideLoopfunction at the very top of your code. Then you won't need to pass the parameter.exit.while (exit !== true) {do stuff}.OutsideLoop()with no argument it isundefined, therefore my comment is correct.