码迷,mamicode.com
首页 > 其他好文 > 详细

for ..break和try ..catch

时间:2015-06-18 16:54:31      阅读:87      评论:0      收藏:0      [点我收藏+]

标签:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
              /*  for (int i = 1; i <= 100; i++)
            {
                Console.WriteLine("hello"+i);
                if (i == 40)
                {
                    break;//终止离它最近的循环,跳出整个循环
                }
            }*/
            /*while (true)
            { string s=Console.ReadLine();
            try//尝试,保护起来,即使程序也能执行出错
            {
                int a = int.Parse(s);
                Console.WriteLine(a);
            }
            catch (Exception b)//捕获错误,有错误才执行
            {
                Console.WriteLine(b);
            }
            finally//不管有没有错最后都执行
            { 
            Console.WriteLine("hello");
            }

            }*/
        }
    }
}

 

for ..break和try ..catch

标签:

原文地址:http://www.cnblogs.com/qixinjian/p/4586120.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!