char status = 'f';
char arr1[11][11];
char arr2[11][11];
......
do{
......
for(int x=0; x<11; x++){
for(int y=0; y<11; y++){
if(temp[x][y]!=store[x][y]){
status='f';
}
else{
status='t';
}
}}
}
while(status != 'f');
......上面是我的do-while循环代码。
据我所知,当while中的条件为真时,程序应该再次从do运行。
假设我的理解是正确的,当temp[x][y]不等于store[x][y]时,程序应该让status = 'f'和循环继续。一旦temp和store相等,status = 't'和循环就会结束。
我现在的问题是,虽然我能够推进循环,但即使temp和store相等,循环也不会结束。我做错了什么?
谢谢!
发布于 2017-11-18 17:12:01
else{
status='t';
break;
}将确保您不会覆盖一旦更改的status。否则就会被覆盖。
以及第一个for循环内部的另一个检查
if ( status == 't') break;
代码将是
do{
status = 't'; // denotes that they are equal intiially.
......
for(int x=0; x<11; x++) {
for(int y=0; y<11; y++) {
if(temp[x][y]!=store[x][y]) {
status='f'; // they are not equal
}
}
if( status == 'f')
break;
}
} while(status == 'f');https://stackoverflow.com/questions/47368750
复制相似问题