026.While 循环语句
2015-10-27 15:35
183 查看
--------------- main.m ---------------
#import <Foundation/Foundation.h>
int main() //
示例一
{
int count = 0;
while (count < 10)
{
NSLog(@"count:%d", count);
count++;
}
NSLog(@"循环结束!");
// 下面是一个死循环
int count2 = 0;
while (count2 < 10)
{
NSLog(@"不停执行的死循环 %d",
count2);
count2--;
}
NSLog(@"永远无法跳出的循环体");
}
--------------- main.m ---------------
#import <Foundation/Foundation.h>
int main() //
示例二
{
int count = 0;
while (count < 10); //
这里的分号导致循环体脱节
// 分号表示一个空语句,不断执行空语句,其实也是死循环
// 下面的代码块与while循环已经没有任何关系
{
NSLog(@"count: %d", count);
count++;
}
}
--------------- main.m ---------------
#import <Foundation/Foundation.h>
int main() //
示例三
{
int count = 10;
while (count)
{
NSLog(@"count: %d", count);
count--;
}
}
一、编写本节代码的具体步骤:
1.参照003节的代码编写步骤。
二、本节代码涉及到的知识点:
1.循环语句通常包含四个部分:①初始化语句 ②循环条件 ③循环体 ④迭代语句
2.在上面的第三份代码中,while (count),就等于 while (count != 0)。
3.break是指跳出此循环,而continue是指跳出本次循环,进入下一次循环。
#import <Foundation/Foundation.h>
int main() //
示例一
{
int count = 0;
while (count < 10)
{
NSLog(@"count:%d", count);
count++;
}
NSLog(@"循环结束!");
// 下面是一个死循环
int count2 = 0;
while (count2 < 10)
{
NSLog(@"不停执行的死循环 %d",
count2);
count2--;
}
NSLog(@"永远无法跳出的循环体");
}
--------------- main.m ---------------
#import <Foundation/Foundation.h>
int main() //
示例二
{
int count = 0;
while (count < 10); //
这里的分号导致循环体脱节
// 分号表示一个空语句,不断执行空语句,其实也是死循环
// 下面的代码块与while循环已经没有任何关系
{
NSLog(@"count: %d", count);
count++;
}
}
--------------- main.m ---------------
#import <Foundation/Foundation.h>
int main() //
示例三
{
int count = 10;
while (count)
{
NSLog(@"count: %d", count);
count--;
}
}
一、编写本节代码的具体步骤:
1.参照003节的代码编写步骤。
二、本节代码涉及到的知识点:
1.循环语句通常包含四个部分:①初始化语句 ②循环条件 ③循环体 ④迭代语句
2.在上面的第三份代码中,while (count),就等于 while (count != 0)。
3.break是指跳出此循环,而continue是指跳出本次循环,进入下一次循环。
相关文章推荐
- setTag()
- 开园了,将以此记录个人web前端之路
- 【句柄和指针】
- j2ee学习struts2 笔记
- 面向对象编程中如何描述对象之间的关系?
- solr-5.3部署到tomcat
- Oracle数据库学习第一天
- 027.Do While 循环语句
- 利用fastjson进行json字符串与对象互转
- docker hub使用
- 028.For 循环
- linux 常用命令
- iOS9问题汇总
- 软件测试中条件覆盖,路径覆盖,语句覆盖,分支覆盖的区别
- 初学NDK
- iOS bundle id的作用
- 讯飞语音识别Android-Demo
- win8系统配置开发环境记录
- 030.For 循环代替 While 循环
- 判断设备的代码