The while (1) { ... last ... } style is clearer and avoids extraneous indentation. The only thing biting me in the past when using this construct is that sometimes I forgot to add the final last, resulting in an infinite loop. But this series-of-checks-and-early-bail pattern happens so often in my code that the construct quickly became second nature.

Anyone got the same habit, or perhaps using some alternative (like the new given-when)?

4 komentar:

Just leave out the 'while (1)' part. If you read the documentation for last it says: "Note that a block by itself is semantically identical to a loop that executes once. Thus "last" can be used to effect an early exit out of such a block."