我需要将此for
小循环转换为while
循环,我该怎么做?
void count_the_numbers(int array[]){
printf("\n");
int i = -1;
while(i < 4){
int count = 1;
i++;
for(int j=0; j < 5; j++){
if(i != j && array[i] == array[j])
count++;
}
printf("Number %d is %d times in this array/e\n", array[i],
conteggio);
}
}
这是另一个循环,给我的结果与上一个不同
将for
回路转换为while
回路纯粹是机械的。给定任何这样的循环:
for(w; x; y) {
z;
}
可以直接将其转换为:
w;
while(x) {
z;
y;
}
唯一的复杂因素(在您的示例中不适用)是,如果for
循环continue
在身体的任何地方使用,则需要y
在每次出现之前将其复制到。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句