1.break与continue.
这两个关键字一般放在循环的花括号里面使用。
break——结束整个循环。
continue——结束本次循环,进入下次循环。

break的案例:
int i = 1;
for(;;)
{
if(i>100)
{
break;
}
Console.Write(i+"\t");
i++;
}

continue的案例:
for (int i = 1; i <= 100; i++)
{
if(i%2 == 0)
{
continue;
}
Console.Write(i + "\t");
}
2.while循环
//初始条件
while(循环条件)
{
//循环体
//状态的改为
}
案例:
int i = 1;
int count=0; //记录与7有关的数字的个数
while(i<=100)
{
if(i%7==0 || i%10==7||i/10==7)
{
Console.Write(i+"\t");
count++;
//1
}
i++;
//2
}
//3
Console.Write("共有"+count+"个与7相关的数");

3.do...while(循环条件)简单了解。
即使初始条件不满足循环条件,循环还会执行一次。
至少执行一次。

数组:解决同一类大量数据在内存存储和运算的功能。
分类:一维数组、二维数组、多维数组。
特点:连续,同一类数据。

一、一维数组:豆角。
定义:指定类型,指定长度,指定名称。
int[] a = new int[5]; //5是长度。从1开始算。默认5个元素初始值都是0.
int[] a = new int[5] { 90, 95, 89, 76, 99 };
int[] a = new int[5] { 90, 95, 89 }; //语法有错,后面初始化的值必须是5个。
int[] a = new int[] { 90, 95, 89, 76, 99}; //计算机会根据后面的赋值,动态计算数组的长度。

赋值:
数组名[下标数值] = 值;
int[] a = new int[5];
a[0] = 10;
a[1] = 20;
a[2] = 30;
a[3] = 40;
a[4] = 50;

取值:
数组名[下标数值]; //下标数值从0开始。
Console.WriteLine(a[3]+a[0]);

数组的好处:
1.对于大量数据来说,保存的时候,定义一个数组即可解决。
2.用循环来控制数组的下标,可以对数组进行批量操作。
例如:
int[] a = new int[5];
//数组的批量赋值
for (int i = 0; i < 5;i++ )
{
a[i] = (i + 1) * 10;
}
//数组的批量取值。
for (int j = 0; j < 5;j++ )
{
Console.WriteLine(a[j]); //0下标。
}

案例一:做一个教练为6个球员打分的程序。
//定义一个保存球员成绩的数组
int[] a = new int[6];

//输入
for (int i = 0; i < a.Length; i++)
{
Console.Write("请输入第"+(i+1)+"个球员的成绩:");
a[i] = Convert.ToInt32(Console.ReadLine());
}

//输出
for(int j=0;j<a.Length;j++)
{
Console.WriteLine("第"+(j+1)+"位球员的分数是"+a[j]+"分。");
}

break与continue的更多相关文章

  1. jquery each函数 break和continue功能

    jquery each函数 break和continue功能幸运的是另一个突破,持续一个jQuery循环方式.你可以打破在函数返回一个jQuery参数虚假循环.一个可以继续执行只是在做不指定返回值或返 ...

  2. break、continue、return

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  3. C语言-循环结构及break、continue

    循环结构 --1-- 结构循环 1.1 while循环 1.2 do…while循环 1.3 for循环 --2-- break和continue 2.1 break关键字 2.2 continue关 ...

  4. 嵌套循环中break、continue的用法

    在循环语句中经常会用到break.continue语句,基本用法如下: 一.break语句为退出当前循环,在嵌套循环中结果如下: var num=0; for(var i=0;i<5;i++){ ...

  5. delphi中break,continue, exit,abort, halt, runerror的异同

    delphi中表示跳出的有break,continue, exit,abort, halt, runerror. 1.break 强制退出循环(只能放在循环中),用于从For语句,while语句或re ...

  6. Delphi中exit、break、continue等跳出操作的区别

    Delphi中表示跳出的有break,continue,abort,exit,halt,runerror等 1.break 强制退出最近的一层循环(注意:只能放在循环里:而且是只能跳出最近的一层循环) ...

  7. C语言break和continue

    break和continue C语言中有有两种结束循环的关键字:break和continue #include <stdio.h> #include <stdlib.h> in ...

  8. 记录今天学习python中for与while循环针对break和continue的用法

    python中有两个主要的循环for与while,其中针对这两个循环有两种不同的中断用法break与continue. 首先先看下面的循环代码: 1: for i in range(10):#变量i带 ...

  9. javascript 中break、 continue、函数不能重载

    在javascript中,break与continue有着显著的差别. 如果遇到break语句,会终止最内层循环,无论后面还有多少计算. 如果遇到continue,只会终止此次循环,后面的自循环依然执 ...

  10. JavaScript If...Else、Switch、For、While、Break、Continue语句

    一,JavaScript If...Else 语句 条件语句 通常在写代码时,您总是需要为不同的决定来执行不同的动作.您可以在代码中使用条件语句来完成该任务. 在 JavaScript 中,我们可使用 ...

随机推荐

  1. bzoj2014 [Usaco2010 Feb]Chocolate Buying

    Description     贝西和其他奶牛们都喜欢巧克力,所以约翰准备买一些送给她们.奶牛巧克力专卖店里 有N种巧克力,每种巧克力的数量都是无限多的.每头奶牛只喜欢一种巧克力,调查显示, 有Ci头 ...

  2. hdu 1010 Tempter of the Bone 深搜+剪枝

    Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe ...

  3. javacript 面向对象

    1.对象 使用Object创建对象 var p = new Object(); p.name = 'jason'; p.sayName = function(){ alert(this.name); ...

  4. flume【源码分析】分析Flume的拦截器

    h2 { color: #fff; background-color: #7CCD7C; padding: 3px; margin: 10px 0px } h3 { color: #fff; back ...

  5. eclipse/myeclipse使用技巧

    热键篇: Template:Alt + / 修改处:Window->Preference->Workbench->Keys->Command->Edit->Cont ...

  6. 配置文件的读取添加webconfig

    webconfig.xml的配置文件内容挺丰富的,在这篇文章里笔者只对AppSettings这个节点进行配置文件读取和添加 public class ConfigurationRef { /// &l ...

  7. uva 10655 - Contemplation! Algebra

    ---恢复内容开始--- Given the value of a+b and ab you will have to find the value of an+bn 给出a+b和a*b的值,再给出n ...

  8. Struts2 访问web元素

    访问web元素的四种方法(耦合,依赖注入).(耦合,非依赖注入).(非耦合,依赖注入).(非耦合,非依赖注入) 耦合:可以得到HttpServletResponse,HttpServletReques ...

  9. C# 利用file打印日志

    public class FaceLog { public static void AppendInfoLog(string errMsg) { try { string Folder = Main. ...

  10. php输出json中文显示编码-解决办法

    $str = "中华人民共和国";$ar = array( "a" => "a0", "b" => &quo ...