Learning point C language (7): For Loop

Source: Internet
Author: User
1. Basic Form of for loop:
 
# Include <stdio. h> int main (void) {int I; for (I = 0; I

2. Step Size:

 
# Include <stdio. h> int main (void) {int I; for (I = 0; I

3. decrease:

 
# Include <stdio. h> int main (void) {int I; for (I = 10; I> 0; I --) {printf ("% d \ n", I );} getchar (); Return 0 ;}

  

4. Available characters:

 
# Include <stdio. h> int main (void) {char C; For (C = 'a'; c --) printf ("% C \ n", C ); getchar (); Return 0 ;}

  

5. decimal places available:

# Include <stdio. h> int main (void) {double F; For (F = 0.0f; f

6. carry other variables:

 
# Include <stdio. h> int main (void) {int I, j = 0; for (I = 0; I
 
# Include <stdio. h> int main (void) {int I, j = 999; for (I = 0; I

7. nesting:

 
# Include <stdio. h> int main (void) {int I, j; for (I = 0; I

8. Break:

 
# Include <stdio. h> int main (void) {int I; for (I = 0; I

9. Continue:

 
# Include <stdio. h> int main (void) {int I; for (I = 0; I

10. omitted:

 
# Include <stdio. h> int main (void) {int I = 0; For (; I
 
# Include <stdio. h> int main (void) {int I; for (I = 0; I ++) {if (I> 10) break; printf ("% d \ n ", i);} getchar (); Return 0 ;}

  
 
# Include <stdio. h> int main (void) {int I; for (I = 0; I
 
# Include <stdio. h> int main (void) {int num = 0; For (;) {printf ("% d \ n", num); num ++; if (Num> 10) break;} getchar (); Return 0 ;}

  

11. Simplify Boolean judgment

# Include <stdio. h> int main (void) {int I; for (I = 10; I> 0; I --) printf ("% d \ n", I ); /* Where I> 0 is a Boolean judgment */for (I = 10; I --) printf ("% d \ n", I ); /* Because I = 0 is false, it can be omitted; this is the same as the previous sentence */getchar (); Return 0 ;}

  

12. Example: the output is an integer ranging from 0 to 100, with 10 line breaks.

 
# Include <stdio. h> int main (void) {int I; for (I = 0; I

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.