Here's an example of where I'm using it in some code...
// This is used to generate edges on turfs as a workaround for layering in SIDE_MAP format |
What are everyones thoughts on using labels for loops and breaking/continuing using those labels? I know that goto is stayed away from (afaik because most people don't know how to use it properly). Is the same animosity attached to loop labels?
Here's an example of where I'm using it in some code...
| ||
#2 Feb 29 2012, 9:13 am
|
|
Are there any advantages or disadvantages performance-wise using labels as opposed to variables like that, or is it mostly a preference for people based on readability?
| |
#3 Feb 29 2012, 10:00 am
|
|
The different in performance should be negligible. If your game's CPU usage is high, this wouldn't be the cause either way. The reason for doing this is readability more than anything else.
I forgot to mention this in the first post: needing loop labels can be a sign that you should split the code into two procs. Though that's probably not the case here. | |
In the code you have there, replacing "continue DIR_LOOP" with "break" would have the same effect (assuming there's not more code following that). Even if there is more code, you can do something like this:
Personally, I don't like loop labels because they look strange (you're never expecting to see them) and they require extra indentation.