0

2 つのオブジェクトの配列を反復処理してそれらを比較するにはどうすればよいですか?ただし、2 回目の反復 (obj2 の場合) で、既に一致することがわかっているオブジェクト (obj1) の比較を除外したいですか? つまり、両方に同じオブジェクトを見つけてほしくありません。

for (object *obj1 in array) 
    if (obj1 == "this") //run next iteration
    for (object *obj2 in array)
    // if (obj2 == @"this");   
4

1 に答える 1

1
for(object *obj1 in array) {
    for (object *obj2 in array) {
        if(obj1 == obj2) continue; //this matches if the object is same
        //do your code
    }
}
于 2013-02-08T05:44:09.597 に答える