C语言将For循环更改为While循环 [英] C language Changing For Loop to While loop
本文介绍了C语言将For循环更改为While循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使 for循环变为 while循环
可以将数组中的 for循环更改为 while循环吗?
How to make for loop to while loop
Is it possible to change for loop in array to while loop?
更改
for(i = 0; i < 12; ++i) //for loop for selecting only positive
{
if(a[i] > 0) printf("%d ", a[i]); //display positive only using if statement
}
to
int i = 0, a[12];
while(i < 12)
{
if(a[i] > 0)
{
printf("%d ", a[i]);
}
i++;
}
但是如果更改,它不会显示与否相同的结果.
but it doesn't display the positive same as the negative if changed..
推荐答案
int i;
for(i=0; i < count; i++)
{
// Work item here
}
在功能上等同于
int i=0;
while (i < count)
{
// Work item here
i++;
}
这篇关于C语言将For循环更改为While循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文