Question about coding style guide at Apple with continue and break keywords

Hi there!

I recently got into a discussion with my Java professor. In her style guide she specifically mentions to never use the break or continue keywords in loops as they are, according to her, outdated and unviable. I have tried to prove by counter example when they are more useful than alternatives, without success.

This has gotten me wondering if these keywords are actually outdated, I am still a student after all. So I wanted to know from someone at Apple if using break or continue is forbidden, discouraged or fine to use (specifically in java but general guidelines are also fine) and why?

Any answer from a current or former Apple employee would help me greatly to have an insight into how the industry handles these keywords and I thank you in advance for your response.

If there is a better place to ask this please direct me towards that.

I've no idea what Apple do. There are various corporate style guides that are available online, including Google's.

The important thing is to understand why these things might be discouraged. If you're smart, you should imagine future-you writing a style guide for your subordinates, not blindly following one written by someone else. (If you're not smart, stop asking questions and just do what you're told!)

Thanks for your answer. I know style guides are available online, the lack of one for apple has brought me here. I checked google's style guide which did not mention these keywords. And yes, this entire post asking why these things might be discouraged because I have not gotten a to me valid answer from my professor except for that it is not necessary to use them (which doesn't explain why it is not allowed). If there is no reason why it would be bad to use, I also learn something so again I would really appreciate a response.

The reason for disliking them is that they permit "less structured" control flow.

GOTO permits totally-unstructured control flow. break and continue are like a restricted form of GOTO.

Structured control flow is preferred because it is easier to correctly understand it when you read it. Remember, the next person who will read the code that you write will be a violent psychopath who knows where you live.

Consider reading Djikstra's "GOTO considered harmful" paper. I don't know if you'll really understand it, but try.

In my opinion, when you consider writing break or continue your should ask yourself "How could I write this otherwise, and would that be more or less clear?". If the alternative would be less clear (to the axe-wielding psychopath), then break and continue are fine.

P.S.

Have a look at the LLVM coding conventions, described here:

https://llvm.org/docs/CodingStandards.html

They say that they actually prefer using continue rather than extra indentation.

This also reminds me that some people say that having multiple return statements in a function is bad.

Interesting, thanks for your help so far.

If the alternative would be less clear (to the axe-wielding psychopath), then break and continue are fine.

I know break and continue are not always the best choice and I fully understand why they wouldn't be. The discussion I was having with my professor was that she said they are never useable and outdated, thus forbidding us from using them which I had issues with, largely consisting of me referencing Linus' Linux style guide and his (in my opinion very valid) issues with too many indentations.

Also don't worry, I am a first year student but I have not just started learning Computer Science. I am happy to hold a discussion at a detailed level (that is what I will learn the most from)

Question about coding style guide at Apple with continue and break keywords
 
 
Q