026.While 循环语句
来源:互联网 发布:关于单片机的毕业设计 编辑:程序博客网 时间:2024/06/09 19:45
--------------- main.m ---------------
#import<Foundation/Foundation.h>
intmain() // 示例一
{
int count = 0;
while(count < 10)
{
NSLog(@"count:%d", count);
count++;
}
NSLog(@"循环结束!");
// 下面是一个死循环
int count2 = 0;
while (count2 < 10)
int count2 = 0;
while (count2 < 10)
{
NSLog(@"不停执行的死循环%d", count2);
count2--;
}
NSLog(@"永远无法跳出的循环体");
}
NSLog(@"永远无法跳出的循环体");
}
--------------- main.m ---------------
#import<Foundation/Foundation.h>
intmain() // 示例二
{
int count = 0;
while (count < 10);// 这里的分号导致循环体脱节
// 分号表示一个空语句,不断执行空语句,其实也是死循环
// 下面的代码块与while循环已经没有任何关系
{
NSLog(@"count: %d", count);
count++;
}
}
}
--------------- main.m ---------------
#import<Foundation/Foundation.h>
intmain() // 示例三
{
int count = 10;
while(count)
{
NSLog(@"count: %d", count);
count--;
}
}
}
一、编写本节代码的具体步骤:
1.参照003节的代码编写步骤。
二、本节代码涉及到的知识点:
1.循环语句通常包含四个部分:①初始化语句 ②循环条件 ③循环体 ④迭代语句
2.在上面的第三份代码中,while (count),就等于 while (count != 0)。
3.break是指跳出此循环,而continue是指跳出本次循环,进入下一次循环。
0 0
- 026.While 循环语句
- 026.While 循环语句
- while语句构成循环
- while语句循环结构
- while循环语句
- for while 循环语句
- do while 循环语句
- MySQL While循环语句
- Python While循环语句
- 循环结构(while语句)
- Python--While循环语句
- Python3-while循环语句
- while循环语句
- JAVA-while循环语句
- Python While 循环语句
- while循环语句
- do.while循环语句
- Python While 循环语句
- Algorithms—141.Linked List Cycle
- init engine failure
- GC类型
- Maven 如何处理传递性依赖
- CodeForces 545E Paths and Trees(最短路)
- 026.While 循环语句
- ios 中frame and bound
- 一次简单的Maven加速构建实战
- 微信平台红包制作基础教程
- 代码审查最佳实践
- 027.Do While 循环语句
- 实训项目
- poj 2904 The Mailboxes Manufacturers Problem( 区间dp)
- C# using简介