循环可以用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 );
时间: 2024-10-15 11:59:28