using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace 第五天_流程控制02
{
class Program
{
static void Main(string[] args)
{
int i = ;
int s = ;
while (i < )
{
if (i % == )
{
s += i;
Console.WriteLine("当前累加到的数字为{0},累加的和为{1}",i,s);
}
i++;
}
Console.ReadKey();
}
}
}

0-100所有偶数相加的结果。

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace 第五天_流程控制02
{
class Program
{
static void Main(string[] args)
{
int i = ;
int j = ;
int s = ;
while (i <= )
{
while (j <= )
{
Console.WriteLine("当前是while循环中的内循环,j的值为{0}",j);
j++;
break;
}
i++;
Console.WriteLine("当前是while循环中的外循环,i的值为{0}", i);
} Console.ReadKey();
}
}
}

break跳出的是当前while循环。

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace 第五天_流程控制02
{
class Program
{
static void Main(string[] args)
{
int _scoreAll = ;
Console.WriteLine("请输入班级总人数:");
int _classNum = Convert.ToInt32(Console.ReadLine());
int i = ;
while (i <= _classNum)
{
Console.WriteLine("请输入第{0}个同学的成绩:",i);
int _scoreMan = Convert.ToInt32(Console.ReadLine());
_scoreAll +=_scoreMan;
i++;
}
Console.WriteLine("全班共有{0}个同学,总成绩为:{1},平均成绩为:{2}",_classNum,_scoreAll,_scoreAll/_classNum);
Console.ReadKey();
}
}
}

while循环结构的应用。

while循环最易遗忘的点是i++。

最新文章

  1. Reverse Core 第一部分 代码逆向技术基础
  2. 应用程序框架实战十三:DDD分层架构之我见
  3. 如何更快的删除String中的空格[未完]
  4. 一段处理百分数的js代码
  5. R----data.table包介绍学习
  6. Android开发(二十八)——基础功能函数
  7. Eclipse在线安装ADT插件
  8. 【工具推荐】ELMAH——可插拔错误日志工具
  9. [OpenGL ES 03]3D变换:模型,视图,投影与Viewport
  10. ContentLoadingProgressBar不显示问题
  11. git submodule 使用过程中遇到的问题
  12. 【.NET Core项目实战-统一认证平台】第十五章 网关篇-使用二级缓存提升性能
  13. DirectX11 With Windows SDK--22 立方体映射:静态天空盒的读取与实现
  14. Team Queue (HDU:1387)
  15. Android环境下hanlp汉字转拼音功能的使用介绍
  16. 全网最详细的Windows里Anaconda-Navigator启动后闪退的解决方案(图文详解)
  17. python学习第38天
  18. 用C#开发基于自动化接口的OPC客户端
  19. C语言程序设计II—第六周教学
  20. UI BOL 练习 get value set attr

热门文章

  1. [趣学程序]java的常用类之String
  2. bytedance专题
  3. Java-Servlet请求方式doXXX、service 具体分析
  4. ES6中比较实用的几个特性
  5. 小白学Python(4)——用Python创建PPT
  6. Nginx总结(一)Linux如何安装Nginx
  7. linux安装杀软 clamAV
  8. Kali-Linux-美化与优化
  9. 剑指Offer(二十二):从上往下打印二叉树
  10. pip安装ansible的过程