Sometimes we may need to execute the same piece of code multiple times. In general, statements are executed sequentially: The first statement in a function executes first, followed by the second statement, and so on.
Programming languages provide a variety of control structures for more complex execution paths.
The loop statement allows us to execute a statement or group of statements multiple times.
650) this.width=650; "Src=" https://s3.51cto.com/wyfs02/M00/9D/F0/wKioL1mJICqSs2DmAABWSVO0OLs147.png-wh_500x0-wm_ 3-wmp_4-s_116382754.png "style=" Float:none; "title=" 2017-08-08_10-10-09.png "alt=" Wkiol1mjicqss2dmaabwsvo0ols147.png-wh_50 "/>
650) this.width=650; "Src=" https://s3.51cto.com/wyfs02/M01/9D/F0/wKioL1mJICvgUbnJAABG0nxDqBo684.png-wh_500x0-wm_ 3-wmp_4-s_3968717418.png "style=" Float:none; "title=" 2017-08-08_10-10-24.png "alt=" Wkiol1mjicvgubnjaabg0nxdqbo684.png-wh_50 "/>
Own little Practice
Print Count
#include <stdio.h>int main () {int a,sum;printf ("Please enter number A:"), scanf ("%d", &a), sum = 1;do{printf ("*"); sum = sum + 1;} while (sum<=a);}
Top N Odd and
#include <stdio.h>int main () {int s,sum,n,i;printf ("Enter the top N:"), scanf ("%d", &n); s = 0;sum = 1;i = 1;while (i<=n ) {s = s +sum;sum = sum + 2;i = i + 1;} printf (the and of the first n items is:%d. ", s);}
Seeking primes
#include <stdio.h> #include "math.h" int main () {int a,n,i;printf ("Please enter the number to be judged: \ n"), scanf ("%d", &a); n = sqrt (a); for (i=2;i<=n;i=i+1) {if (a%n==0) break;} if (i==n+1) printf ("%d" is a prime number.) ", a); else printf ("%d is not a prime number.) ", a);}
This article from "Big Plum" blog, reproduced please contact the author!
C-language loop structure and cyclic control statements