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

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.

主站蜘蛛池模板: 平罗县| 斗六市| 右玉县| 垣曲县| 宣汉县| 莎车县| 呼伦贝尔市| 宁陕县| 皮山县| 武乡县| 青田县| 依兰县| 榆树市| 锦屏县| 平遥县| 和田市| 甘南县| 基隆市| 兴仁县| 前郭尔| 婺源县| 酒泉市| 普宁市| 大埔县| 左权县| 崇明县| 永川市| 陆川县| 石阡县| 昌图县| 平安县| 扎兰屯市| 雷山县| 页游| 金山区| 浏阳市| 库伦旗| 屏东县| 江口县| 开江县| 图木舒克市|