---------------------- Windows Phone 7手机开发、.Net培训、期待与您交流! ----------------------
break;//终止while循环,继续while后面的代码
continue;//终止while本次循环,继续while后面的代码
return;//终止当前执行的函数,后续的代码也不会被执行
using System;
using System.Collections.Generic;
using System.Text;
namespace 循环终止
{
class Program
{
static void Main(string[] args)
{
/*
int i = 0;
while (i < 12)
{
Console.WriteLine("i={0}",i);
i++;
if (i == 10)
{
break;//终止while循环,继续while后面的代码
continue;//终止while本次循环,继续while后面的代码
return;//终止当前执行的函数,后续的代码也不会被执行
}
Console.WriteLine("自增以后i={0}",i);
}
Console.WriteLine("before ReadKey");
*/
//用while continue实现计算1到100之间的处理能被7整除之外所有的证书的和
int sum = 0;
int i = 1;
while (i<=100)
{
if (i % 7 == 0)//数如果被7整除余数为0,则说明能别整除
{
i++;//不要丢!i不会自己增加!最常见的错误!
continue;
}
sum = sum + i;
i++;
}
Console.WriteLine("{0}",sum);
Console.ReadKey();
}
}
}
---------------------- Windows Phone 7手机开发、.Net培训、期待与您交流! ----------------------