In Java, C, and C++ we have the following jump statements: break, continue, goto, and return. In C#, there is also throw.

I'm not really familiar with either of these languages. This is simply what I have read on the web.

All these jump statements are unconditional. I tried to find mention about conditional jump statements, but all links lead to Assembly.

Is it correct to say that conditional jump statements exist in Assembly only?

Some people on the Internet are telling me that if is actually a conditional jump statement, but I don't think so. At least, it's not described as such in Microsoft or QT documentation.

Regarding comments to this question:

How are if or switch ... case are not conditional jump statements? Why do you think these aren't? – πάντα ῥεῖ

@πάνταῥεῖ - As I see it, if, switch, return, break etc. are control flow statements. Jump statements are a subset of them. And please note that neither Microsoft, nor QT, nor any another documentation treat if as a jump statement.

The difference between control flow statements and jump statements, as I see it, is described here: https://www.inf.unibz.it/~calvanese/teaching/06-07-ip/lecture-notes/uni06/node45.html

有帮助吗?

解决方案

The distinction which the linked source makes is unclear.

In my view, the distinction it is making is between structured flow control statements, and unstructured flow control statements.

A "conditional jump" is simply an if statement and the like. if is also a structured statement. Most structured languages don't expose an unstructured conditional jump statement (although it exists at the assembly level).

An "unconditional jump" is a goto statement and the like. goto is also considered an unstructured statement, although in structured languages nowadays there are often constraints on exactly what it can do. An example of a "structured unconditional jump", is a function call - the function will always be jumped into (which is what makes it unconditional), but it must also jump back (which is what makes it structured).

break and continue are often regarded as the last vestiges of unstructured flow control, although they are by definition local to a structured flow control statement.

The distinctions between "conditional" and "structured" flow control statements are wholly orthogonal.

I will add as well, a sensible definition of a "flow control statement" is one which is capable of causing code to be executed other than that on the very next line. A conditional jump is one which jumps away from the next line in some cases. An unconditional jump is one which jumps away from the next line in all cases.

其他提示

It’s trivial in most languages to compose a conditional jump from existing features, for example

If (x > 0) goto y;

So there is very little demand for a conditional jump statement, and therefore you don’t see it. Having a statement like

Ifgoto (x > 0, y); 

Would seem unnecessary, confusing, and stupid.

许可以下: CC-BY-SA归因
scroll top