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

  • How are if or switch ... case are not conditional jump statements? Why do you think these aren't? – πάντα ῥεῖ May 8 at 8:46
  • 1
    @πάνταῥεῖ As I see it, if, switch, return, break etc. are conditional jump statements. Jump statements is a subset of conditional jump statements. And please note that neither Microsoft, nor QT, nor any another documentation treat if as a jump statement. – john c. j. May 8 at 8:50
  • 1
    Well, you could add some details to your question (e.g. what your definition of a jump statement is) to improve it. – πάντα ῥεῖ May 8 at 9:00
  • @πάνταῥεῖ Done. – john c. j. May 8 at 9:01
  • 2
    Also: Java and C++ also have throw, and Java doesn't have goto. – Alexander - Reinstate Monica May 10 at 18:22

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.

| improve this answer | |
  • 1
    @john-c-j,gosub is antiquated, and I've never seen a real piece of code that uses it. It is unstructured in the sense it jumps into the middle of a method, notwithstanding (iirc) that it returns to the call site. I would treat it as an unstructured statement, although some of these arguments raged 40 years ago. Arguably (I write in a state of inebriation), structured code corresponds with indentation, with decisions being at the same level of indentation. If you can jump into the middle of a block, it's unstructured. – Steve May 8 at 23:59
  • 1
    @johnc.j. Gosub would be structured so long as you must return to the call point. It’s how you call a subroutine. The modern form of that is calling a void “function”. – candied_orange May 9 at 4:01
  • 1
    @john-c-j, I'd broadly agree with that. I'd suggest that the word "jump" has acquired the implication of being both unstructured and unconditional. Because, as I say, modern languages only expose conditional jumps as structured statements, these structured statements are not jumps by that definition (because a jump is something that defies the tenets of structured programming), and it is not then necessary to emphasise the unconditionality of the remaining unconditional jumps either, because they are the only kind. – Steve May 9 at 11:43
  • 1
    Obviously though, if you go down to the assembly level, structured statements cease to exist, and the conditional jump is an elementary instruction, so the word "jump" can no longer carry the baggage it does for those who spend all their time in structured languages. – Steve May 9 at 11:53
  • 1
    @john-c-j, no I said that break and continue are unstructured jumps, albeit that they occur within structured blocks. So also is return an unstructured jump, when it occurs elsewhere than at the end of the method. Structured statements are (I hazard the following definition offhand...) those in which there is a block with one entry, one exit, execution progresses linearly from entry to exit, and in which any conditions for entry or exit (including iterations which move from exit back to entry, or decisions which determine entry into subsidiary blocks) are stated at the start of the block. – Steve May 10 at 18:54

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.

| improve this answer | |
  • 1
    I think the crux is that in structured languages, the if and the goto are considered two separate statements, consisting of an unconditional jump within a conditional block (rather than an conditional jump). But in C's terse syntax, this pair of statements is scarcely any longer than the shortest conceivable single statement which expresses a conditional jump. It is not immediately apparent why a goto y if x; is confusing or stupid, but it is certainly unnecessary in C given that it is no shorter or structurally simpler than the shortest two-statement alternative if (x) goto y; – Steve May 12 at 17:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.