While reading a topic in my book on comparison between java and c ++ ... I read one difference .....

java statements can be labeled while c++ statements cant be. Can anybuddy tell the use of labeling in java?

Recommended Answers

All 2 Replies

I assume you are refering to labels like this? http://www.janeg.ca/scjp/flow/labels.html

I personally never use labelling in Java and I rarely see it used. To me it feels like a primitive feature that I'd use back with asm compilers. I think it is good programming practice to avoid constructs that resemble GOTO. Code with GOTOs are generally harder to follow.

Most of the time, I use break and continue without labels. I think the only example of code that I can remember in recent memory that could have benefitted from labels for an parameter-search/optimization problem similar to the basic artificial intelligence algorithm A-Star. Oh actually... I wrote some C code to do with cache tiling optimizations in the processor that might have benefitted from labels, but usually these are exceptions to the rule.


Thanks for all that ... but I needed to know how it works... cuz even if I dont use it in my code ... its not good that I dont learn it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.