![]() ![]() In languages where indentation matter, those "changes" that do nothing may be confusing when you later go through your or someone else's commits. Indentation changes show up in git (unless you configure otherwise). contunue saves some headache.Īlso, if you already wrote some code and only later realised you have some border cases, you can add a similar 'skip' thingy to the beginning of the loop and don't indent the rest. That could make a lot of indentation levels or scopes that is hard to manage. Then check its value - if it's something strange, again skip. check whether some property exist - if not, skip the rest for that element. imagine having a lot of cases you must skip the entry. ![]() continue is basically the same as putting everything below in else.īut if that else part is long or uses a lot of indentation levels, and maybe some loops by itself, continue and break save a lot of space and allow for easier flow management!Į.g. There's no difference in how the code works. Is there an intended difference? Are there cases where one is quicker, more readable, etc? If we had incremented the variable i after the continue statement, it would be an infinite loop after i =5.To me there is no difference in what can be achieved with these two structures. Why? When i> 7, i is also greater than 5 and the continue statement is executed thus ignoring the break statementīe Careful when using break, pass, and continue statements.
0 Comments
Leave a Reply. |