This is a curiosity I’ve had for far too long. Why didn’t I make these simple tests years ago when I was first learning AS3? I’m not sure, but judging by a lot of other people’s AS3 that I’ve read, many people don’t seem to understand it.

What does this print?

trace("before");
for (var i:* in null)
{
	trace("inside");
}
trace("after");
 
trace("before");
for each (var j:* in null)
{
	trace("inside");
}
trace("after");

Does the loop crash on the null when it tries to iterate over it? Would it necessitate the kinds of null checking I’ve seen so often in AS3 code? Nope! The for-in and for-each loops conveniently and efficiently skip the loop and we get:

before
after
before
after

On that happy note, enjoy your weekend!