简单,可复制

点点滴滴,尽在文中

  :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

循环可以用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 );





posted on 2011-12-13 18:10  ggjucheng  阅读(2864)  评论(0编辑  收藏  举报