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