While loop only responding to second condition
<p>My while loop is only ending when it matches the second condition, the first one is being ignored, I have no idea what I am doing wrong</p>

<pre><code>while (response !=0) or (cont != 5):
    response = os.system("ping -c 2 " + hostname)
    cont=cont+1
    print cont
    print response
</code></pre>

<p>Change your <code>or</code> to <code>and</code>. When it is checking the first condition and if that is false and the second condition is true, whole condition will be true. It means either first condition is true or second condition is true.</p>

<pre><code>While ( false or true ) will be while ( true )
</code></pre>

<p>To check both the condition you should use <code>and</code>. It checks that both conditions should be <code>true</code> for the expression to be <code>true</code>.</p>

<pre><code>while ( false and true ) will be while ( false )

while (response !=0) and (cont != 5):
    response = os.system("ping -c 2 " + hostname)
    cont=cont+1
    print cont
    print response
</code></pre>

python