先说Foreach和For的区别,Foreach是针对对象进行遍历的,不需要定义循环次数,但是有个缺点,Foreach遍历取的是只读数据,不能在Foreach中进行对象的增删改,而For循环就可以。你这个改成while循环的代码如下:
| 代码如下 |
复制代码 |
|
int i=0;while(i
|
例
| 代码如下 |
复制代码 |
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 中断循环
{
class Program
{
static void Main(string[] args)
{
//100以内拍七
int i = 0;
while (i < 100)
{
i++;
if(i%7==0 || i%10==7||i/10==7)
{
continue;
}
Console.WriteLine("{0}",i);
}
Console.ReadKey();
}
}
}
|
while中return,continue,break的区别。
return:退出main函数
continue:直接进行下轮循环
break:直接跳出当前循环