WordPress loop add heading before first of type

You could try a concept like the following (post your loop and I will improve the model):

$state_group = 'Open Loop';

// start the loop
// if posts then while

$state_code = // lookup this post state code
if ( $state_code != $state_group ){
    echo $state_code; 
    $state_group = $state_code;
}

//end loop