C# 中的 continue 语句有点像 break 语句。但它不是强制终止,continue 会跳过当前循环中的代码,强制开始下一次循环。

对于 for 循环,continue 语句会导致执行条件测试和循环增量部分。对于 while 和 do while 循环,continue 语句会导致程序控制回到条件测试上。

提示:C# continue 语句必须在循环语句中使用。

EX.打印出1-20之间的偶数

using System;

namespace KingTest03
{
class Program
{
static void Main(string[] args)
{
Program program = new Program();
program.even(); }
public void even()//输出1-20之间的偶数
{
for (int i = ; i < ; i++)
{
if (i%!=) {
continue;//当i的余数不等于0的时候,就跳出循环执行下一次循环。
}
Console.WriteLine(i);
}
}
}
}

猜数字例子:

using System;
namespace _break
{
class class1
{
static void Main()
{
int input, randomNum, countfirst, countend;
bool exit = false;
countend = ;
countfirst = ; do
{
Random rand = new Random();
randomNum = rand.Next(, );
Console.WriteLine("你有5次机会猜数字,请输入1-100的整数,剩余次数为{0}", countend - countfirst);
try
{
input = Convert.ToInt32(Console.ReadLine());
if (input < | input > )
{
Console.WriteLine("请输入1-100的整数");
}
else if (input > randomNum)
{
Console.WriteLine("随机数是{0},你猜测数字是{1},恭喜你,你大", randomNum, input);
countfirst++;
if (countfirst > countend)
{
Console.WriteLine("您已经猜测没有次数了");
break;
} }
else if (input < randomNum)
{
Console.WriteLine("随机数是{0},你猜测数字是{1},恭喜你,你大", randomNum, input);
countfirst++;
if (countfirst > countend)
{
Console.WriteLine("您已经猜测没有次数了");
break;
} }
else
{
Console.WriteLine("恭喜你,猜对了");
break;
} }
catch (Exception)
{ Console.WriteLine("请输入整数"); }
} while (true);
}
}
}

最新文章

  1. 8.dns服务的搭建
  2. View绘制机制
  3. [Android]Android开发入门之HelloWorld
  4. ldap + kerberos + google authentication 实现两步验证
  5. 原生js事件委托
  6. LeetCode:Maximum Depth of Binary Tree_104
  7. PAT A 1013. Battle Over Cities (25)【并查集】
  8. HDU 5919 Sequence II 主席树
  9. AlwaysON同步性能监控的三板斧
  10. Solr部署如何启动
  11. apple iphone 3gs 有锁机 刷机 越狱 解锁 全教程(报错3194,3014,1600,短信发不出去等问题可参考)
  12. Selenium webdriver 查找元素
  13. Python:黑板课爬虫闯关第四关
  14. (转)Microsoft Print to PDF
  15. python学习笔记之函数的参数
  16. 设置JVM参数的几种方式解决java.lang.OutOfMemoryError:Java heap space
  17. Smooth Face Tracking with OpenCV
  18. (用了map) Registration system
  19. 记一次线上gc调优的过程
  20. Windows命令行使用总结(持续更新)

热门文章

  1. 剑指Offer-42.和为S的两个数字(C++/Java)
  2. [CodeForces-1225B] TV Subscriptions 【贪心】【尺取法】
  3. Shape.Type属性名称及对应值列表
  4. Java描述设计模式(04):抽象工厂模式
  5. [Spring cloud 一步步实现广告系统] 4. 通用代码模块设计
  6. 使用Kubernetes进行ProxySQL本机群集
  7. kali安装openvas
  8. OpenCV:图像的合并和切分
  9. 你以为的Jquery选择器是什么样子的?
  10. 使用 TSPITR 恢复删除的表空间的步骤 (Doc ID 1277795.1)