吴裕雄--天生自然C语言开发:循环
while(condition)
{
statement(s);
}
#include <stdio.h> int main ()
{
/* 局部变量定义 */
int a = ; /* while 循环执行 */
while( a < )
{
printf("a 的值: %d\n", a);
a++;
} return ;
}
for ( init; condition; increment )
{
statement(s);
}
#include <stdio.h> int main ()
{
/* for 循环执行 */
for( int a = ; a < ; a = a + )
{
printf("a 的值: %d\n", a);
} return ;
}
do
{
statement(s); }while( condition );
#include <stdio.h> int main ()
{
/* 局部变量定义 */
int a = ; /* do 循环执行 */
do
{
printf("a 的值: %d\n", a);
a = a + ;
}while( a < ); return ;
}
for (initialization; condition; increment/decrement)
{
statement(s);
for (initialization; condition; increment/decrement)
{
statement(s);
... ... ...
}
... ... ...
}
while (condition1)
{
statement(s);
while (condition2)
{
statement(s);
... ... ...
}
... ... ...
}
do
{
statement(s);
do
{
statement(s);
... ... ...
}while (condition2);
... ... ...
}while (condition1);
#include <stdio.h> int main ()
{
/* 局部变量定义 */
int i, j; for(i=; i<; i++) {
for(j=; j <= (i/j); j++)
if(!(i%j)) break; // 如果找到,则不是质数
if(j > (i/j)) printf("%d 是质数\n", i);
} return ;
}
#include <stdio.h>
int main()
{
int i=,j;
while (i <= )
{
j=;
while (j <= i )
{
printf("%d ",j);
j++;
}
printf("\n");
i++;
}
return ;
}
#include <stdio.h>
int main()
{
int i=,j;
do
{
j=;
do
{
printf("*");
j++;
}while(j <= i);
i++;
printf("\n");
}while(i <= );
return ;
}
#include <stdio.h> int main ()
{
/* 局部变量定义 */
int a = ; /* while 循环执行 */
while( a < )
{
printf("a 的值: %d\n", a);
a++;
if( a > )
{
/* 使用 break 语句终止循环 */
break;
}
} return ;
}
#include <stdio.h> int main ()
{
/* 局部变量定义 */
int a = ; /* do 循环执行 */
do
{
if( a == )
{
/* 跳过迭代 */
a = a + ;
continue;
}
printf("a 的值: %d\n", a);
a++; }while( a < ); return ;
}
goto label;
..
.
label: statement;
#include <stdio.h> int main ()
{
/* 局部变量定义 */
int a = ; /* do 循环执行 */
LOOP:do
{
if( a == )
{
/* 跳过迭代 */
a = a + ;
goto LOOP;
}
printf("a 的值: %d\n", a);
a++; }while( a < ); return ;
}
#include <stdio.h> int main ()
{
for( ; ; )
{
printf("该循环会永远执行下去!\n");
}
return ;
}
吴裕雄--天生自然C语言开发:循环的更多相关文章
- 吴裕雄--天生自然 R语言开发学习:R语言的安装与配置
下载R语言和开发工具RStudio安装包 先安装R
- 吴裕雄--天生自然C语言开发:结构体
struct tag { member-list member-list member-list ... } variable-list ; struct Books { ]; ]; ]; int b ...
- 吴裕雄--天生自然C语言开发:约瑟夫生者死者小游戏
个人在一条船上,超载,需要 人下船. 于是人们排成一队,排队的位置即为他们的编号. 报数,从 开始,数到 的人下船. 如此循环,直到船上仅剩 人为止,问都有哪些编号的人下船了呢? #include&l ...
- 吴裕雄--天生自然 R语言开发学习:数据集和数据结构
数据集的概念 数据集通常是由数据构成的一个矩形数组,行表示观测,列表示变量.表2-1提供了一个假想的病例数据集. 不同的行业对于数据集的行和列叫法不同.统计学家称它们为观测(observation)和 ...
- 吴裕雄--天生自然 R语言开发学习:高级编程
运行的条件是一元逻辑向量(TRUE或FALSE)并且不能有缺失(NA).else部分是可选的.如果 仅有一个语句,花括号也是可以省略的. 下面的代码片段是一个例子: plot(x, y) } else ...
- 吴裕雄--天生自然 R语言开发学习:模块\包的安装命令
install.packages('模块包名称') 或者 install.packages('模块包名称',repos='http://cran.us.r-project.org')
- 吴裕雄--天生自然 R语言开发学习:集成开发环境\工具RStudio的安装与配置
- 吴裕雄--天生自然C语言开发:错误处理
#include <stdio.h> #include <errno.h> #include <string.h> extern int errno ; int m ...
- 吴裕雄--天生自然C语言开发:强制类型转换
#include <stdio.h> int main() { , count = ; double mean; mean = (double) sum / count; printf(& ...
随机推荐
- springboot自动装配介绍
所谓的自动装配,就是 autowire. 如何激活自动装配呢? 方法一:@EnableAutoConfiguration或@SpringBootApplication,写在@Configuration ...
- python刷LeetCode:21. 合并两个有序链表
难度等级:简单 题目描述: 将两个有序链表合并为一个新的有序链表并返回.新链表是通过拼接给定的两个链表的所有节点组成的. 示例: 输入:1->2->4, 1->3->4输出:1 ...
- Mybatis实现增删改查(二)
1. 准备 请先完成Mybatis基本配置(一)的基本内容 2. 查询多条商品信息 1)在com.mybatis.dao.PartDao中增加接口函数 public List<PartInfo& ...
- Navicat Premium 12.0.18 安装与激活
Navicat Premium 12.0.18中文版 百度云链接:https://pan.baidu.com/s/1HHOOlQbbWAL-MlI908n4MQ 提取码:k9w6 1.下载好后双击运行 ...
- eclipse中tomcat添加或移除web项目出错,显示无资源能被添加或移除
错误截图 之前一直都能正常使用,今天莫名其妙出现这个错误 解决办法 https://blog.csdn.net/u012956987/article/details/79134474 右击项目,在属性 ...
- LNMP安装问题
查什么占用了端口 netstat -nlp |grep :80 root@zzx:/usr/local/mysql# netstat -nlp |grep :80tcp 0 ...
- JS用例
showBtn :class="{getInput:showBtn}"v-if="showBtn" showBtn: true, this.showBtn = ...
- 201503-2 数字排序 Java
思路: 将出现过的数以及次数放进Map中,转成List,用Comparator就可以排序了.参数中o2-o1,与排序规则相反,为降序 import java.util.ArrayList; impor ...
- c# 异常处理 try --catch
初学 try---catch 语法 try { 可能会出现异常的代码; 异常出现的那行代码下面的代码全不会执行,直接跳到catch中执行 ... ... } //try和catch之间不能有其他的代码 ...
- MyBatis从入门到精通(第4章):MyBatis动态SQL【foreach、bind、OGNL用法】
(第4章):MyBatis动态SQL[foreach.bind.OGNL用法] 4.4 foreach 用法 SQL 语句中有时会使用 IN 关键字,例如 id in (1,2,3).可以使用 ${i ...