第7讲循环结构(二)分解.ppt

第8讲 循环结构 二 一、continue 语句和 break 语句 二、循环的嵌套 三、goto语句 一、continue 语句和 break 语句 1、continue语句 1 格式:continue ; 2 功能:结束本次循环,使程序回行到循环条件,判断是否提前进入下一次循环。   3 说明:continue语句只能用于循环结构的内部,并常与if语句联合起来使用,以便在满足条件时提前结束本次循环。 写出下面程序的结果。 continue 语句的使用 #include void main int i, s; s 0; for i 1; i 10 ; i++ if i%2 continue; s s+i; printf s %d\n,s ; 执行结果:   s 30 写出下面程序的结果。 continue 语句的使用 #include void main int i, s; i 0; s 0; while i 10 i++; if i%2 0 continue; s s+i; printf s %d\n,s ; 执行结果:   s 36 例 求1~100中非5的倍数的所有数的和。 main int i,s; s 0; for i 1;i 100;i++ if ! i

文档评论(0)

1亿VIP精品文档

相关文档