Will 30 GOTO 10 always go to 10?

半腔热情 提交于 2019-12-03 21:32:29

No, it will not. But it will always behave as if it did. One of the basic rules in compiler design is the "as if" rule. Your compiler can make whatever changes it likes, as long as the result is going to behave as if you'd followed the language rules.

GOTO 10 may decide to jump to some other location, as long as the compiler can guarantee that it won't change the outcome of the program.

So no, it shouldn't worry you.

Not if you've got

40 COMEFROM 30

somewhere in your code.

DJ.

Well, it won't if it doesn't execute, for example if there's a 20 GOTO 40.

In BASIC, yes. In other languages, it will generate a compile error.

What are you trying to say? Anyone claiming to be a programmer should know (especially after your hint) that it depends on what's on lines 10 and 20, and anyone who's been on SO for longer than a week should realize that this question doesn't seem to add much.

We should rely on the code doing exactly what we tell it to. If we tell it to GOTO 10 on line 30, but also tell it to skip line 30, we shouldn't be the least surprise when line 30 is skipped. We told the program to.

True, if you consider multi-core CPUs executing a BASIC program, one of the cores might accidentally miss the GOTO (hint: "TLB Bug") and continue as if it weren't there.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!