-
#include <stdio.h>
-
-
int main ()
-
{
-
/* local variable definition */
-
int a = 10;
-
-
/* do loop execution */
-
LOOP:do
-
{
-
if( a == 15)
-
{
-
/* skip the iteration */
-
a = a + 1;
-
goto LOOP;
-
}
-
printf("value of a: %d\n", a);
-
a++;
-
-
}while( a < 20 );
-
-
return 0;
-
}
value of a: 10
value of a: 11
value of a: 12
value of a: 13
value of a: 14
value of a: 16
value of a: 17
value of a: 18
value of a: 19
-
// goto_statement.cpp
-
#include <stdio.h>
-
int main()
-
{
-
int i, j;
-
-
for ( i = 0; i < 10; i++ )
-
{
-
printf_s( "Outer loop executing. i = %d\n", i );
-
for ( j = 0; j < 2; j++ )
-
{
-
printf_s( " Inner loop executing. j = %d\n", j );
-
if ( i == 3 )
-
goto stop;
-
}
-
}
-
-
// This message does not print:
-
printf_s( "Loop exited. i = %d\n", i );
-
-
stop:
-
printf_s( "Jumped to stop. i = %d\n", i );
-
}
Outer loop executing. i = 0
Inner loop executing. j = 0
Inner loop executing. j = 1
Outer loop executing. i = 1
Inner loop executing. j = 0
Inner loop executing. j = 1
Outer loop executing. i = 2
Inner loop executing. j = 0
Inner loop executing. j = 1
Outer loop executing. i = 3
Inner loop executing. j = 0
Jumped to stop. i = 3
阅读(822) | 评论(0) | 转发(0) |