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