Can a bad program lead to lost Cloud connection?

Yes, you can write code that renders your Photon inable to reach the cloud.

Unless you are using dedicated SYSTEM_MODEs or the new beta multithreading feature SYSTEM_THREAD(ENABLED) any code that prevents your program from leaving loop() while not calling delay() or Particle.process() will most likely break the cloud connection.

But if you've got a very fresh Photon and flashed it the first time, it might rather be that the auto firmware update might have come in your way
Read this