跳转到内容

Cpp class index:修订间差异

HanyuTech留言 | 贡献
HanyuTech留言 | 贡献
 
(未显示同一用户的4个中间版本)
第79行: 第79行:
=== 基本程序结构 ===
=== 基本程序结构 ===


基本结构对比
==== 结构演示 ====


加链接到各个例子
'''顺序结构'''


加基本结构流程图


结构的嵌套
'''分支结构'''
 
if 单分支
 
http://static.hanyu123.cn/wiki/images/cpp-structure-if.gif
 
if-else 双分支
 
http://static.hanyu123.cn/wiki/images/cpp-structure-if-else.gif
 
嵌套的if-else多重分支
 
http://static.hanyu123.cn/wiki/images/cpp-structure-multi-if-else.gif
 
switch分支
 
http://static.hanyu123.cn/wiki/images/cpp-structure-switch.jpg
 
'''循环结构'''
 
while循环
 
http://static.hanyu123.cn/wiki/images/cpp-structure-while.gif
 
do-while循环
 
http://static.hanyu123.cn/wiki/images/cpp-structure-do-while.gif
 
for循环
 
http://static.hanyu123.cn/wiki/images/cpp-structure-for.jpg
 
==== 结构比较 ====
 
'''while语句和do-while 语句的区别'''
 
while语句先判断条件是否为真,为真时执行,并循环判断、执行。
 
do-while语句先执行,再判断条件是否为真,为真时继续执行,并循环判断、执行。
 
do-while语句至少会执行1次。如果初始条件就是false,while语句执行0次。
 
'''for语句和while/do-while 语句的区别'''
 
for语句一般用来执行次数提前确定好的循环。由控制变量来控制次数。
 
while语句、do-while语句的循环次数可以是不定的。由条件是否成立来控制是否继续循环。