140
rated 0 times
[
145]
[
5]
/ answers: 1 / hits: 35406
/ 11 Years ago, mon, february 3, 2014, 12:00:00
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!);
}
};
More From » javascript