官术网_书友最值得收藏!

  • Learn C# in 7 days
  • Gaurav Aroraa
  • 163字
  • 2021-07-08 09:51:29

The for loop

The for loop is similar to other loops that help run a statement or code block repeatedly until an expression evaluates to false. The for loop takes three sections: the initializer, condition, and iterator, where the initializer section executes first and only once; this is nothing but a variable to start a loop. The next section is condition, and if it evaluates to true, then only body statements are executed; otherwise it terminates the loop. The third and most important section is incremental or iterator, which updates the loop control variable. Let's take a look at the following code snippet:

private static void ForStatementExample() 
{ 
WriteLine("for loop example."); 
Write("Enter repeatitive length:"); 
int length = Convert.ToInt32(ReadLine()); 
for (intcountIndex = 0; countIndex < length; countIndex++) 
    { 
     WriteLine(newstring('*', countIndex)); 
    } 
}

The preceding code snippet is a working example of a for loop. Here, our code statement within the for loop block will executive repeatedly until the countIndex&lt; length expression evaluates to false.

主站蜘蛛池模板: 嘉荫县| 根河市| 桃园县| 手游| 潍坊市| 金塔县| 洮南市| 屏南县| 德安县| 惠东县| 孝感市| 嘉兴市| 通江县| 景宁| 历史| 乐昌市| 北宁市| 株洲县| 祁门县| 连云港市| 高阳县| 油尖旺区| 马公市| 庆城县| 郑州市| 江山市| 大同县| 西昌市| 临高县| 博兴县| 阳城县| 邵阳县| 隆回县| 当雄县| 通辽市| 汨罗市| 白银市| 通河县| 民权县| 平昌县| 工布江达县|