码迷,mamicode.com
首页 > 其他好文 > 详细

4.循环语句

时间:2015-03-04 14:15:34      阅读:136      评论:0      收藏:0      [点我收藏+]

标签:

循环可以用while,do,for,goto语句表述

    while (condition) statement;

    do statement while(condition);

    for (for-init-statement; condition; expression) statement;

    goto identifier;

     identifier: statement;

while语句代码段

int a = 0;
while( a > 0 )
{
a--;
}

do语句代码段

int a = 0;
do
{
a--;
}
while( a > 0 );

for语句代码段

技术分享
int sum = 0;
int i;

for( i=1; i <= 100;i++)
{
sum += i;
}
技术分享


goto语句

技术分享
int i, j;

for ( i = 0; i < 10; i++ )
{
printf( "Outer loop executing. i = %d\n", i );
for ( j = 0; j < 2; j++ )
{
printf( " Inner loop executing. j = %d\n", j );
if ( i == 3 )
goto stop;
}
}

// This message does not print:
printf( "Loop exited. i = %d\n", i );

stop:
printf( "Jumped to stop. i = %d\n", i );
技术分享

4.循环语句

标签:

原文地址:http://www.cnblogs.com/aibiancheng/p/4313012.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!