Control flux in python if/elif continue
<p>I have a <code>if</code>/<code>elif</code> statement in Python, but I want to execute both commands next. I want to show <code>AD0</code> and <code>AD1</code> every second, but the code is just showing <code>AD1</code> (Not entering on <code>elif</code>).</p>

<pre><code>#!/usr/bin/env python
# -*- coding: utf-8 -*-
import serial
from time import sleep
import datetime

now = datetime.datetime.now()

port = '/dev/ttyUSB0'
ser = serial.Serial(port, 9600, timeout=0)

while True:
    arquivo = open('temperatura.txt','r')
    conteudo = arquivo.readlines()
    now = datetime.datetime.now()

    data = ser.read(9999)
    if len(data) &gt; 0:
        if 'AD0'in data:
            temp = data[4:7]
            #print 'Got:', data
            #string = str('A temperatura Ã©',temp,'ÂºC')             
            conteudo.append(now.strftime("%Y-%m-%d %H:%M"))
            conteudo.append(' ')
            conteudo.append('[AD0]A temperatura Ã©')
            conteudo.append(temp)
            conteudo.append('ÂºC')           
            print '[AD0]A temperatura Ã©',temp,'ÂºC'
            #print string 
            conteudo.append('\n')
            arquivo = openarquivo = open('temperatura.txt','w')
            arquivo.writelines(conteudo)
            continue

        elif 'AD1'in data:
            temp = data[4:7]
            #print 'Got:', data
            #string = str('A temperatura Ã©',temp,'ÂºC')             
            conteudo.append(now.strftime("%Y-%m-%d %H:%M"))
            conteudo.append(' ')
            conteudo.append('[AD1]A temperatura Ã©')
            conteudo.append(temp)
            conteudo.append('ÂºC')           
            print '[AD1]A temperatura Ã©',temp,'ÂºC'
            #print string 
            conteudo.append('\n')
            arquivo = openarquivo = open('temperatura.txt','w')
            arquivo.writelines(conteudo)   

    sleep(1)
    #print 'not blocked'
    arquivo.close()

ser.close()
</code></pre>

<p>Python will pick the <em>first</em> matching condition out of a series of <code>if..elif..</code> tests, and will execute just that <em>one</em> block of code.</p>

<p>If your two tests should be <em>independent</em> and both should be considered, replace the <code>elif</code> block with a separate <code>if</code> statement:</p>

<pre><code>if 'AD0'in data:
    # ...

if 'AD1'in data:
    # ...
</code></pre>

<p>Now both conditions will be tested independently and if both match, both will be executed.</p>

python if-statement