Unable to upload code to Arduino Uno R3...

Arduino board details:
Arduino Uno R3(Original),
Made in Italy.

PC OS is Windows 8.1,

Arduino IDE ver. :1.6.5.

A code which uses IR Sensors (required for line following robot) was uploaded onto arduino.
The arduino with the code on it worked fine but it did not allow further uploading of any code.
I tried ‘reset’ button but it didn’t work. In fact it just restarted the code from beginning.
And the error during uploading is:
avrdude: ser_open(): can’t open device “\.\COM3”: The system cannot find the file specified.

I think it may be due to the code that is running on arduino (executing loop() function ) engaging the board and not allowing further uploads.

I have already made sure that i have been using the correct COM port. I also have the required drivers installed on my PC.

Awaiting any suggestions or fixes to this problem…
and of course Thanks in advance.

That error message indicates that COM3 (the selected port) does not exist at the time you are attempting to upload. Check tools -> port menu, make sure that you have selected a port that is present on that list.

Be aware that the port number will often change depending on which USB port the device is plugged into, and sometimes Windows just changes it for the hell of it when a device is reconnected.

If you are getting that error, it has nothing to do with the code that you've previously uploaded, or the code you're currently trying to upload.

I see only one port in my IDE named as "COM3:Arduino/Genuino Uno" and it is selected.

Maybe the code on the arduino wouldn't be of any problem for uploading, but I don't see any other issue that can cause this.