玖叶教程网

前端编程开发入门

C语言(五):for,break,continue(c语言for break用法)


分享兴趣,传播快乐,
增长见闻,留下美好!
亲爱的您,这里是LearningYard新学苑。
今天小编为大家带来的是C语言(五):for,break,continue。


Share interests, spread happiness,

increase knowledge, and leave good!

Dear you, this is the Learning Yard.

Today, Xiaobian brings you

C language (V): for, break, continue.


01

for语句和循环嵌套

(1)循环的基本结构

初始化计数器、循环条件、更新计数器

(1) The basic structure of the loop

initializes counters, loop conditions, and updates counters


(2)for语句

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

表达式1为初始化表达式

表达式2为循环条件表达式

表达式3为循环调整表达式

(2) For statement

for (expression 1; expression 2; expression 3)

expression 1 is initialization expression

expression 2 is circular condition

expression 3 is circular adjustment expression

(3)灵活的for语句

表达式1,2,3可以按照需求进行省略(分号不能省略)

while(1):永远为真的循环

(3) Flexible for statement

Expressions 1, 2 and 3 can be omitted as required (semicolon cannot be omitted)

While (1): loop that is always true


(4)循环嵌套

例:九九乘法表

(%-2d:使输出的int型的数值以2位的固定位宽输出。若不足2位,则在右边补空格)

(4) Loop nesting

Example: 99 multiplication table

(% - 2d: make the output value of int type output with a fixed bit width of 2 bits. If it is less than 2 bits, fill a space on the right)


02

break语句和continue语句

(1)break语句

(1) Break statement


跳出内层循环:

Jump out of the inner loop:


跳出外层循环:

Jump out of the outer loop:


(2)continue语句

(2) Continue statement


(3)whil语句与for语句不能完全等价

(3) While statement and for statement cannot be completely equivalent


无法执行:

Unable to execute:


可执行:

Executable:

END


今天的分享就到这里了。
如果您对今天的文章有独特的想法,
欢迎给我们留言,
让我们相约明天,
祝您今天过得开心快乐!


That's all for today's sharing.

If you have unique ideas about today's article,

please leave us a message.

Let's meet tomorrow and wish you a happy day!


翻译:百度翻译
参考:《零基础入门学习C语言:带你学C带你飞》、哔哩哔哩小甲鱼视频、网络图片
声明:本文由LearningYard新学苑原创,若有侵权请联系删除!

关注我们

文案&排版:易春秀

审核:闫庆红

发表评论:

控制面板
您好,欢迎到访网站!
  查看权限
网站分类
最新留言