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

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.

主站蜘蛛池模板: 绥芬河市| 桐城市| 雷山县| 恩施市| 犍为县| 琼海市| 娱乐| 和硕县| 类乌齐县| 安龙县| 西畴县| 海晏县| 无极县| 凤山县| 南通市| 泽库县| 永泰县| 加查县| 蚌埠市| 炉霍县| 阿瓦提县| 丹东市| 莱芜市| 阳西县| 汝州市| 巴中市| 历史| 淮滨县| 保山市| 青海省| 庆城县| 奉贤区| 禹州市| 江阴市| 阳泉市| 绥中县| 沂南县| 许昌市| 夏津县| 古蔺县| 浏阳市|