In C using Xcode, how to change the while loop to mach the first for loop?
#include <stdio.h>
int main (int argc, const char * argv[])
{
int i;
i = 0;
while ( i++ < 4)
printf ("while: i%d\n",i);
printf ("after while loop, i=%d\n\n", i );
for (i = 0; i < 4; i++)
printf ("first for: i=%d\n", i );
printf ("after first loop, i=%d\n\n", i );
for ( i= 1; i <=4; i++)
printf ("second for: i=%d\n", i );
printf ("after second loop, i=%d\n", i );
return 0;
}
To change
whileloop toforloop:To make
whileloop print numbers like theforloop:Or alternatively:
Read about pre-increment vs post-increment to get the idea. For example, here.