For else loop in Javascript?

javascript

Solution

Working example (you need to use the flag):

var search = function(num){
    var found = false;
    for(var i=0; i<5; i++){
        if(i===num){
            console.log("Match found: "+ i);
            found = true;
            break;
        }
    }
    if(!found){
        console.log("No match found!");
    }
};

Problem

Is there a Javascript equivalent of the python 'for-else' loop, so something like this: ``` searched = input("Input: "); for i in range(5): if i==searched: print("Search key found: ",i) break else: print("Search key not found") ``` Or do I just have to resort to a flag variable, so something like this: ``` var search = function(num){ found = false; for(var i in [0,1,2,3,4]){ if(i===num){ console.log("Match found: "+ i); found = true; } } if(!found){ console.log("No match found!"); } }; ```

Original source

Related problems