0

我需要比较 cours Nand2Tetris 中的两个数组

let arrayIsOK = true;
let i = 0;
while(i<5){
    if (~(arrayLevel1[i]=arrayLevel2[i])){
        let arrayIsOK = false;
        //do Output.printInt(i);
        do Output.printString(arrayLevel1[i]);
        do Output.printString(" ");
        do Output.printString(arrayLevel2[i]);
        do Output.println();
    }
    let i = i + 1;
}
if (arrayIsOK){
    do Output.printString("GOOD!!!");
}
else{
    do Output.printString("NOT GOOD!!!");
}

但是退货不好!!!

4

1 回答 1

0

你不把 if 的结果放在 {} 你应该这样写

let arrayIsOK = true;
let i = 0;
while(i<5) 
{
    if (~(arrayLevel1[i]=arrayLevel2[i]))
      {
        let arrayIsOK = false;
       }
        //do Output.printInt(i);
        do Output.printString(arrayLevel1[i]);
        do Output.printString(" ");
        do Output.printString(arrayLevel2[i]);
        do Output.println();
    }
    let i = i + 1;
}
if (arrayIsOK){
    do Output.printString("GOOD!!!");
}
else{
    do Output.printString("NOT GOOD!!!");
}
于 2014-02-27T17:24:43.250 回答