-3

I was looking in the Eclipse code styles, to modify the formatting, and came across this:

void foo()
{
    ;;
    label: do
    {
    } while (false);
}

What is the meaning of the first line in foo() (the ";;")?

James Monger
  • 10,181
  • 7
  • 62
  • 98
  • 1
    please take a look at this: http://stackoverflow.com/questions/7081339/what-does-for-mean-in-java – nano_nano Apr 02 '13 at 13:58
  • 2
    because a small google search and you would find the answer by yourself(even for the edited question)... – nano_nano Apr 02 '13 at 14:06
  • I found information about using it in for(;;) but I couldn't find any information about using it as a standalone statement. – James Monger Apr 02 '13 at 14:06
  • yes, but if I may say so: if one uses an endless loop, it only means that the precondition for the loop lacks logic. – GameDroids Apr 02 '13 at 14:13

6 Answers6

3

There is none. It just shows, that before the label there can be something. But as the name empty statement already says: it's empty so there is nothing to compute.

GameDroids
  • 5,584
  • 6
  • 40
  • 59
  • So it's completely ignored by the compiler? – James Monger Apr 02 '13 at 14:00
  • @JamesMonger it won't be ignored, but it doesn't make any sense to begin with. – Luiggi Mendoza Apr 02 '13 at 14:00
  • yes, the compiler should ignore it. @Luiggi: I have to correct me, it is not ignored right away. The Compiler takes everything under consideration, so even the empty statement. But it also cleans up the code and tries to improve it (a little bit). – GameDroids Apr 02 '13 at 14:02
  • 1
    @JamesMonger - I'd actually say that the compiler doesn't "ignore" it. Rather it compiles it to whatever it means in the context; i.e. nothing. It is sort of like saying 'a + 0' in maths. You don't exactly ignore the zero. Rather you rewrite the formula in a simpler form. – Stephen C Apr 02 '13 at 14:08
2

first line

;;

is an empty statements, it does not affect on code because java use ; to terminate line.

and

for(;;)

control goes into infinite loop.

user2236292
  • 235
  • 2
  • 4
1

From the JLS:

An empty statement does nothing.

EmptyStatement:
   ;

You've got 2 empty statements that do nothing.

Reimeus
  • 158,255
  • 15
  • 216
  • 276
0

;; means nothing (nothing will be compute, like 2 empty lines)

for (;;) means infinite loop

TheEwook
  • 11,037
  • 6
  • 36
  • 55
0

Well, this is a template. I guess that line has to be completed with local variable declarations.

manix
  • 11
  • 2
  • I don't see any Java template code anywhere in this example. If you mean a code template, well, you really have lot of imagination to give a template that gives nothing. – Luiggi Mendoza Apr 02 '13 at 14:01
  • 1
    @LuiggiMendoza, did you read the original question? I stated that it was part of the Eclipse code formatting examples, there was other code in the method but I wanted to know why there were two semicolons in the code - I did not write it. – James Monger Apr 02 '13 at 14:03
  • @JamesMonger no I haven't since **you change the whole question content** which means your question loses its meaning (altogether with the answers). Next time you edit your question to add new info, please **just add it** and **do not delete** the relevant previous info. – Luiggi Mendoza Apr 02 '13 at 14:04
  • 1
    I used template as synonym for example. You insert the code template and that complete it. – manix Apr 02 '13 at 14:05
  • 1
    @LuiggiMendoza I didn't change the whole question content, I removed the "for(;;)" line because I know what "for(;;)" does and so I didn't want people to think that I was asking about that. I didn't remove relevant info, I removed irrelevant info so that people would fully understand my question - the part about it being from Eclipse was never removed! – James Monger Apr 02 '13 at 14:06
0

Empty statement. It means: don't do anything. It is rarely useful, but as any other statement it can be used in if:

if(something)
    ;
else
    doSomething();

or while:

while(a[i++] != 0)
    ;

Doesn't look like good style anyway.

zch
  • 14,931
  • 2
  • 41
  • 49