Examples of how while and for can be converted to each other are Shared
- 2020-04-02 02:13:51
- OfStack
//While and for loops can be converted to each other in the following simple format;
for(1;2;3)
A;
//Is equivalent to
//1 ;
while(2)
{
A;
3;
}
# include <stdio.h>
int main(void)
{
int i = 1,sum= 0;
while(i<=100)
{
sum+=i;
++i;
}
printf("%dn", sum);
return 0;
}
/*
----------------------
The code by C-Free 5.0 Write and output debugging results
----------------- The output ---------------
5050
------------ conclusion ------------
while and for Interchangeable, but used while Should be
Notice the order. The order is for The order of the loop.
*/