免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 723 | 回复: 0
打印 上一主题 下一主题

The Continue and Break [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-12-21 08:41 |只看该作者 |倒序浏览
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. }
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP