2014-04-13第15周周日:goto语句的标志只包含一句话,而且程序总会执行goto的标志。
来源:互联网 发布:淘宝客服常见问题汇总 编辑:程序博客网 时间:2024/06/11 16:01
对于下面这段代码,
int main(){int i, j;for ( i = 0; i < 10; i++ ){printf( "Outer loop executing. i = %d\n", i );for ( j = 0; j < 3; j++ ){printf( " Inner loop executing. j = %d\n", j );if ( i == 10 )goto stop;printf( " i = %d , j = %d \n",i, j );}}/* This message does not print: */printf( "Loop exited. i = %d\n", i );stop: printf( "Jumped to stop. i = %d\n", i );//stop: 就是标签 return 0;}
最后两行显示的是:
Loop exited. i =10Jumped to stop.i=10可见,程序未执行goto stop;这条语句,但还是经过了stop的标志。
以下代码是执行了goto stop;这条语句并跳到stop标志处的情况(只是将以上程序的if(i==5)改成了if(i==10)):
#include <stdio.h>int main(){int i, j;for ( i = 0; i < 10; i++ ){printf( "Outer loop executing. i = %d\n", i );for ( j = 0; j < 3; j++ ){printf( " Inner loop executing. j = %d\n", j );if ( i == 5 )goto stop;printf( " i = %d , j = %d \n",i, j );}}/* This message does not print: */printf( "Loop exited. i = %d\n", i );stop: printf( "Jumped to stop. i = %d\n", i );//stop: 就是标签 return 0;}
最后三行显示的是:
Outer loop executing. i=5Inner loop executing. j=0Jumped to stop. i=5
1 0
- 2014-04-13第15周周日:goto语句的标志只包含一句话,而且程序总会执行goto的标志。
- GOTO 语句的魅力
- goto语句的使用
- 尴尬的goto语句
- 古老的goto语句
- delphi的goto语句
- goto语句的用法
- 有趣的goto语句
- 只执行一次的标志位
- 2014-03-13周四:有意思的goto语句。。。
- goto 语句跳不出无限循环,但之后的循环体表达式不执行了,只执行步进和判断
- 21、goto语句的使用
- 取代goto语句的方法
- 有争议的goto语句
- delphi Goto 语句的使用
- 关于goto语句的使用
- goto语句的“跳跃”问题
- c语言的goto语句
- PAT 1002. 写出这个数 (20)
- Android搜索错误no such column
- HTTP深入浅出 http请求
- Unity3D使用SVN或GIT版本控制
- 项目5--复制类模板
- 2014-04-13第15周周日:goto语句的标志只包含一句话,而且程序总会执行goto的标志。
- week after week----友情岁月,匆匆
- stat函数与结构体
- TCP的三次握手,四次挥手
- 找到eclipse的入口了
- 堆和栈的区别
- tar 解压缩命令
- Delphi利用系统环境变量获取常用系统目录
- VMware虚拟机磁盘分区图文教程