即使在到达for
语句之后,在函数内部的return
循环中进行迭代,循环仍会无限进行。
此时,j
大于lister.length
。它退出了for
循环,并在函数结束时以看似无限的电路跳回到了for
循环。
这种行为对我来说没有意义,因为return
语句应终止该函数。
这是我的功能:
function permutationLoop(originalArray, listOfPermutations) {
// generates a permutation(Shuffle),and makes sure it is not already in the list of Perms
var lister = generatingPerms(originalArray, listOfPermutations);
//adds the permutation to the list
listOfPermutations.push(lister);
var tester = true;
//This for loop looks through the new permutation to see if it is in-order.
for (var j = 0; j < lister.length; j++) {
//This if statement checks to see as we iterate if it is in order
if (lister[j] > lister[j + 1]) {
tester = false;
}
if (j == (lister.length - 1) && tester == true) {
//Return the permutation number that found the ordered array.
return listOfPermutations.length;
//THIS IS NOT EXITING THE LOOP
}
if (j == lister.length - 1 && tester == false) {
permutationLoop(originalArray, listOfPermutations);
}
}
}
答案 0 :(得分:1)
您的if语句可能无效
尝试通过fun testStuff(type: Class<out Bag<Int>>)