循环语句总结

  • 分类

  • 循环语句的语法

  • cotinue和break语句

  • 总结

一,分类

循环语句有:while循环,do....while循环,for 循环

二、语句特点

1)while 循环

while (表达式)

        循环语句

eg:

#include <stdio.h>
int main()
{
    int i = 0;
    while (i < 3)
    {
        printf("%d\n", i);
        i++;
    }
    system("pause");
    return 0;
}

在while循环中

continue语句用于跳过continue后面的语句直接跳到循环判断部分,看是否满足循环条件; 

break语句用于永远的终止循环,

我们来看一下具体的执行过程

2)for循环

for(表达式1;表达式2;表达式3)

        循环语句;

 eg:

#include <stdio.h>
int main()
{
    int i;
    for (i = 0; i < 10;i++)    
    {
        printf("%d\n", i);
    }
    system("pause");
    return 0;
}

 3)do......while循环

do

        循环语句;

while(表达式)

 eg:

#include <stdio.h>
int main()
{
    int i=1;
    do
    {
        printf("%d\n", i);
        i++;
    } while (i <= 10);
    system("pause");
    return 0;
}

 总结:1.在三种循环中,for循环语法简单,适用性较广范;

2.三种语句中break的用法都是跳出循环体;continue都是跳到判断处

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值