using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace _16.流程控制之while循環 { class Program { static void Main(string[] args) { /** * while循環語句 * 其語法: * while<Test> * { * <code to be looped> * } * * 執行過程: * 1. 計算<Test>布爾表達式的值; * 2. 如果<Test>布爾表達式的值爲true,則執行標記爲循環的代碼; * 3. 如果<Test>布爾表達式的值爲false,則退出循環執行循環結構外的代碼; * 4. 如果<Test>布爾表達式的值爲true時,則重複1~3步驟。 * * 特殊說明: * 1. do...while語句中的循環體至少被執行一次,而while語句中循環體可能不被執行。 * 2. while語句後面不用書寫分號。 * */ // 求2+4+...+10計算的結果。 int i = 2, sum = 0; do { sum += i; i += 2; } while (i <= 10); Console.WriteLine("2+4+...+10 = {0}", sum); Console.ReadKey(); } } }
十六、流程控制之while循環
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.