Test nested for tags and add an optimization condition.