Chinaunix首页 | 论坛 | 博客
  • 博客访问: 21911
  • 博文数量: 10
  • 博客积分: 251
  • 博客等级: 二等列兵
  • 技术积分: 125
  • 用 户 组: 普通用户
  • 注册时间: 2011-02-10 16:30
文章分类
文章存档

2011年(10)

我的朋友
最近访客

分类: 嵌入式

2011-06-26 16:40:21

Can you understand how to use the "continue" and "break"?
This is a example that you can see.
  1. /*
  2.  * Created by SharpDevelop.
  3.  * User: Soledad
  4.  * Date: 2011/6/26
  5.  * Time: 15:50
  6.  *
  7.  * To change this template use Tools | Options | Coding | Edit Standard Headers.
  8.  */
  9. using System;
  10. //using System.Collections.Generic;

  11. //using System.Text;



  12. namespace Welcome
  13. {
  14.      #region The Method Main()
  15.     class Program
  16.     {
  17.         public static void Main(string[] args)
  18.         {
  19.             Console.WriteLine("Hello World!");
  20.             Test();
  21.             //ContinueBreak1 CB = new ContinueBreak1();

  22.             //CB.Test();

  23.             Test2();
  24.             // TODO: Implement Functionality Here

  25.             Console.Write("Press any key to continue . . . ");
  26.             Console.ReadKey(true);
  27.         }
  28.         #endregion
  29.         
  30.         #region The Method Test()
  31.         static int Test()
  32.         {
  33.             int MyInt = 7;
  34.             Console.WriteLine("Initialized,myInt:{0}",MyInt);
  35.             MyInt = 5;
  36.             Console.WriteLine("After assignment,myInt:{0}",MyInt);
  37.         return 0;
  38.         }
  39.         #endregion
  40.         
  41.         #region The ContinueBreak
  42.         static void Test2()
  43.         {
  44.              string signal = "0";//初始化

  45.             while(signal != "x")//x表示终止

  46.             {
  47.                 Console.Write("Enter a singal:");
  48.                 signal = Console.ReadLine();
  49.                 
  50.                 /*
  51.                  * 无论收到什么信号,都要做一些工作
  52.                  */
  53.                 Console.WriteLine("Received:{0}",signal);
  54.                 
  55.                 if(signal == "A")
  56.                 {
  57.                     /*
  58.                      * A表示错误信号___终止信号处理
  59.                      */
  60.                     Console.WriteLine("Fault!Abort\n");
  61.                     break;
  62.                 }
  63.                 
  64.                 if(signal == "0")
  65.                 {
  66.                     Console.WriteLine("All is well.\n");
  67.                     continue;
  68.                 }
  69.                 Console.WriteLine("{0}--raise alarm!\n",signal);
  70.             }
  71.         }
  72.         #endregion    
  73.     }
  74. }
阅读(861) | 评论(0) | 转发(0) |
0

上一篇:C# 名字空间

下一篇:class And object_One

给主人留下些什么吧!~~