What happens when we create the TCP connection and we wait while(1) i.e. infinite loop, Does it get terminated automatically? or It will last forever if my connection is very good
Considering you are not sending any traffic, connection quality has no impact here, because TCP connection on your end-host will not terminate even if you cut the cable between the end-hosts, as long as you don't use optional TCP Keepalive.
In real life networks this is not a very practical way of keeping the connection alive. Firewalls and NATs will eventually flush out the state of this connection in their database, causing the data you might want to transmit at a later time to be dropped, triggering the re-transmission mechanisms in your end-host TCP stack that will eventually lead to session termination.