Chinaunix首页 | 论坛 | 博客

Lzy

  • 博客访问: 208265
  • 博文数量: 56
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 675
  • 用 户 组: 普通用户
  • 注册时间: 2014-02-27 15:50
文章分类

全部博文(56)

文章存档

2014年(56)

我的朋友

分类: C/C++

2014-06-22 10:46:27


点击(此处)折叠或打开

  1. #include <stdio.h>
  2.  
  3. int main ()
  4. {
  5.    /* local variable definition */
  6.    int a = 10;

  7.    /* do loop execution */
  8.    LOOP:do
  9.    {
  10.       if( a == 15)
  11.       {
  12.          /* skip the iteration */
  13.          a = a + 1;
  14.          goto LOOP;
  15.       }
  16.       printf("value of a: %d\n", a);
  17.       a++;
  18.      
  19.    }while( a < 20 );
  20.  
  21.    return 0;
  22. }
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

点击(此处)折叠或打开

  1. // goto_statement.cpp
  2. #include <stdio.h>
  3. int main()
  4. {
  5.     int i, j;

  6.     for ( i = 0; i < 10; i++ )
  7.     {
  8.         printf_s( "Outer loop executing. i = %d\n", i );
  9.         for ( j = 0; j < 2; j++ )
  10.         {
  11.             printf_s( " Inner loop executing. j = %d\n", j );
  12.             if ( i == 3 )
  13.                 goto stop;
  14.         }
  15.     }

  16.     // This message does not print:
  17.     printf_s( "Loop exited. i = %d\n", i );
  18.     
  19.     stop:
  20.     printf_s( "Jumped to stop. i = %d\n", i );
  21. }
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


阅读(771) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~