C语言第七节 FOR 语句

说明:因为正在探讨微信公众号,新浪博客和本博客联动,所以可能不系统,不连贯。所以,请同时关注我的微信公众号(Mark学编程)目前微信公众号最为系统。今后,尽量在这里最全最系统。
我还是喜欢用英语来描述有关定义。
There are plenty of different ways to write a program for a particular task. For example, while and for and do-while can be used to do the same job. As we know, these are called iterative control statements. And these statements allow us to execute one or more program statements repeatedly. Now Let’s study the for statement.
The general format of the for statement is:

for (initial expression; continue condition; increment expression)
{
statement;
statement;
......
statement;
}

The for statement is a loop, a generalization of the while. if you compare it with previous learned while, its operation looks more clear.
after for there is a parenthese, there are three parts, separated by semicolons. The initial expression is executed before the loop proper is entered. The second part is the test or condition that controls the loop.This continue condition is evaluated. if it is true, the body of the loop is executed. Then the increment expression is executed and the continue condition re-evaluated.The loop terminates if the continue condition has become false. The initial, continue and increment can be any expressions.
中文解释:注意不是严格的英语翻译,只是为了充分表达。
for 循环语句格式是
先写for后面加个括号,括号内有三部分。第一部分是循环变量赋初值,在进入循环前执行,第二部分是循环条件,求这个表达式的值,如果为true,则执行循环语句,就是大括号内的语句。然后执行第三部分。 再然后重新开始第二部分,如果第二部分求值为false,则整个循环结束。另外大括号一般称作循环体。
相信已经说的很清楚了,这个for和while有什么区别,练习的多了,自然清楚了,学习编辑就是不断写代码,测试代码。下面举两个例子,请自行运行测试。后面的是一个嵌套的for.

int main()
{
int i;
for ( i=1; i <= 10; i++)
{
prinft ("%d\n", i);
}
return 0;
}
int main()
{
int num, i;
printf ("please input a number ");
scanf ("%d", &num);
printf ("Number    Square   Cube\n");
printf ("--------------------------------------\n");
for ( i = 1; i <=num; i++)
{
printf ("%4d    %4d   %4d\n", i, i * I, i * i * i);
}
return 0;
}

一定要测试吆。
今天就到这里。明天再见,你可以关注我的微信公众号–Mark学编程,也可以关注我的微博博客也是Mark学编程。当然csdn也是尽量和其他两个同步。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

UncleMark编程

获取价值后的回馈,谢谢!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值