问题
How to make for loop to while loop
Is it possible to change for loop in array to while loop?
change
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..
回答1:
int i;
for(i=0; i < count; i++)
{
// Work item here
}
is functionally equivalent to
int i=0;
while (i < count)
{
// Work item here
i++;
}
来源:https://stackoverflow.com/questions/64972464/c-language-changing-for-loop-to-while-loop