nov
2009
Nested Code Blocks
Personally when I code I like to try and be as clear and as explicit as possible. I also really like keeping code tidy. I'm a bit fanatic about it.
Rather than doing;
for i in range(10): if i != 5: # lots # of # lines # of # code # here
Try doing this;
for i in range(10): if i = 5: continue # lots # of # lines # of # code # here
It's more explicit and clear what you are doing. Also, it saves that extra indentation. This example is trivial on purpose to show the change clearly but it does mean in this case it's not that much of a problem. However, when lines of code are tabbed1 in more than maybe four times it starts to get nasty.
This is a minor change but I think it makes things much clearer. The same technique can be used in a function too by using return rather than continue.
-
Ok, so I know it's all spaces really but tabs are easier to talk about. ↩
Short url - Related tags: code-style