Can you understand how to use the "continue" and "break"?
This is a example that you can see.
- /*
- * Created by SharpDevelop.
- * User: Soledad
- * Date: 2011/6/26
- * Time: 15:50
- *
- * To change this template use Tools | Options | Coding | Edit Standard Headers.
- */
- using System;
- //using System.Collections.Generic;
- //using System.Text;
- namespace Welcome
- {
- #region The Method Main()
- class Program
- {
- public static void Main(string[] args)
- {
- Console.WriteLine("Hello World!");
- Test();
- //ContinueBreak1 CB = new ContinueBreak1();
- //CB.Test();
- Test2();
- // TODO: Implement Functionality Here
- Console.Write("Press any key to continue . . . ");
- Console.ReadKey(true);
- }
- #endregion
-
- #region The Method Test()
- static int Test()
- {
- int MyInt = 7;
- Console.WriteLine("Initialized,myInt:{0}",MyInt);
- MyInt = 5;
- Console.WriteLine("After assignment,myInt:{0}",MyInt);
- return 0;
- }
- #endregion
-
- #region The ContinueBreak
- static void Test2()
- {
- string signal = "0";//初始化
- while(signal != "x")//x表示终止
- {
- Console.Write("Enter a singal:");
- signal = Console.ReadLine();
-
- /*
- * 无论收到什么信号,都要做一些工作
- */
- Console.WriteLine("Received:{0}",signal);
-
- if(signal == "A")
- {
- /*
- * A表示错误信号___终止信号处理
- */
- Console.WriteLine("Fault!Abort\n");
- break;
- }
-
- if(signal == "0")
- {
- Console.WriteLine("All is well.\n");
- continue;
- }
- Console.WriteLine("{0}--raise alarm!\n",signal);
- }
- }
- #endregion
- }
- }
阅读(897) | 评论(0) | 转发(0) |