Remove a category from a post when saving a new post

Your foreach doesnt have brackets or semicolons, probably thatś why.
and also not very well idented.
Here it is the code properly idented, just one maybe, the foreach closing brackets probably must be after the return like in the code bellow, or maybe right before. if this code doesnt work cut and paste “return;” to right after the “endforeach;”.

function save_category($post_ID){                                     // get all posts using 'First post' category
  $categories =  wp_get_object_terms( $post_ID, 'First post' );
  if ($categories) {                                                  // query to get posts using 'First post' category
    foreach ($categories as $key => $category) :
      if ($category->name == "First post") {                          // if post is using 'First post' category then remove the category
        wp_remove_object_terms( $post_ID, 'First post', 'category' );
      }
      return;
    endforeach;
  }
  wp_set_post_categories( $post_ID, get_cat_ID( "First post" ) );     // Add 'First post' to post when saving
}
add_action('save_post', 'save_category');