zoukankan      html  css  js  c++  java
  • .Net基础篇_学习笔记_第六天_For循环语法

    For循环:专门处理已知循环次数的循环。  小技巧:连续敲击两下TAB键循环体自动搭建完成。

    For循环语法:

    for(表达式1;表达式2;表达式3)
    {
    循环体;
    }
    表达式1一般为声明循环变量,记录循环的次数(int i=0;)
    表达式2一般为循环条件(i<10)
    表达式3一般为改变循环条件的代码,使循环条件终有一天不再成立(i++)。


    For循环执行过程:

    程序首先执行表达式1,声明了一个循环变量用来记录循环的次数,
    然后执行表达式2,判断循环条件是否成立,如果表达式2返回的结果为true,
    则执行循环体。当执行完循环体后,执行表达式3,然后执行表达式2继续判断循环条件是否成立,
    如果成立则继续执行循环体,如果不成立,则跳出for循环。

     1 namespace 第六天_do_while循环
     2 {
     3     class Program
     4     {
     5         static void Main(string[] args)
     6         {
     7             int i = 1;
     8             while (i<=10)
     9             {
    10                 Console.WriteLine("我很好,我很快乐,我是最棒的,我一定行");
    11                 i++;
    12             }
    13             Console.ReadKey();
    14       
    15         }
    16     }
    17 }

    由while循环转为for循环:

     1 namespace 第六天_do_while循环
     2 {
     3     class Program
     4     {
     5         static void Main(string[] args)
     6         {    
     7             for (int i = 1; i <=10; i++)
     8             {
     9                 Console.WriteLine("我很好,我很快乐,我是最棒的,我一定行");
    10             }
    11             Console.ReadKey();
    12         }
    13     }
    14 }

     for更规范的方式:

     1 namespace 第六天_do_while循环
     2 {
     3     class Program
     4     {
     5         static void Main(string[] args)
     6         {    
     7             for (int i = 0; i <10; i++)
     8             {
     9                 Console.WriteLine("我很好,我很快乐,我是最棒的,我一定行{0}",i);
    10             }
    11             Console.ReadKey();
    12         }
    13     }
    14 }
  • 相关阅读:
    CTF-pwn-tips-zh_CN
    Linux 内核中 offset_of 和 container_of 宏的实现
    glibc2.26 -- tcache (2)
    glibc2.26 -- tcache (1)
    漏洞复现 -- 条件竞争 -- TOCTOU
    Linux 内核源码分析 -- read
    ospf lsa 4是不可替代的
    MPLS_Lab_3_AToM
    配置多链路捆绑PPP
    OSPF在转换LSA 5时的转发地址抑制 cyrus
  • 原文地址:https://www.cnblogs.com/NBOWeb/p/7210119.html
Copyright © 2011-2022 走看看