有人知道如何在一个for循环中遍历两个数组吗?
function setwinner() internal returns(address){
for (uint stime = 0 ; stime < squareStartTimeArray.length; stime++ & uint etime = 0; etime = squareEndTimeArray.length etime++) {
if (winningTime >= stime & winningTime <= etime) {
winningIndex = stime;
if (assert(stime == etime) == true) {
winningAddress = playerArray[stime];
}
}
}
}
要在同一个循环中遍历多个数组,首先应该确保它们都具有相同的长度。然后你可以这样写:
require(arrayOne.length == arrayTwo.length)
for (i; arrayOne.length > i; i++) {
arrayOne[i] = ....;
arrayTwo[i] = ....;
}