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

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.

主站蜘蛛池模板: 鄯善县| 南召县| 巴林左旗| 营山县| 永平县| 文山县| 项城市| 沈阳市| 海淀区| 华池县| 钟山县| 磐安县| 和政县| 淮滨县| 和田市| 鲜城| 岱山县| 武城县| 赤水市| 渭源县| 游戏| 宁化县| 绥宁县| 彩票| 沧州市| 慈溪市| 怀化市| 桑植县| 宁化县| 溧水县| 澄城县| 边坝县| 资阳市| 古蔺县| 永州市| 绩溪县| 林西县| 湟源县| 铅山县| 卢龙县| 焦作市|