alternating control flow with conditionals or preprocessor
<p>Given this code:</p>

<pre><code>for i in range(5):
  foo(i)
  bar(i)
</code></pre>

<p>I want to add some code between the two <code>print</code> lines such that I can break the loop into two, but only if a certain flag is true, i.e.:</p>

<pre><code>for i in range(5):
  foo(i)

if debug: {
  continue
for i in range(5):
}

  bar(i)
</code></pre>

<p>Unfortunately this is not valid python. Is there a way I can do that without manually rewriting the loop to:</p>

<pre><code>if debug:
  for i in range(5):
    foo(i)
  for i in range(5):
    bar(i)
else:
  for i in range(5):
    foo(i)
    bar(i)
</code></pre>

<p>Hmmm we can always store mid-air result in list </p>

<pre><code>n = range(10) 
if debug:
    n = list(map(lambda x: foo(x),n))+list(map(lambda x: bar(x),n))
else:
    n = list(map(lambda x: [foo(x),bar(x)],n))
</code></pre>

python