How to get country list array with their corresponding country codes
You get the infinite loop, because the country name is a translatable markup and print_r() can't handle this object. If you cast the country name to a string, then it is printable in php:

 $countries = \Drupal\Core\Locale\CountryManager::getStandardList();
 foreach ($countries as $key =&gt; $value) {
   $country_name = (string) $value;
   print "$key - $country_name\n";
 }


This is not needed for rendering, because twig can handle this object. This is only for debugging.