title: JUMP_FORWARD or JUMP_ABSOLUTE with IF statement ? Python 2.5
body: <p>I have been using '<a href="http://docs.python.org/2/library/dis.html" rel="noreferrer">dis</a>' module in order to re-write some compiled script (.pyc). I understand the difference between JUMP_FORWARD and JUMP_ABSOLUTE. To my knowledge an IF statement will be closed by a JUMP_FORWARD:</p>
  <pre><code>&gt;&gt;&gt; def f():
          if a:
                  print ''
  &gt;&gt;&gt; from dis import dis
  &gt;&gt;&gt; dis(f)
    2           0 LOAD_GLOBAL              0 (a)
                3 JUMP_IF_FALSE            9 (to 15)
                6 POP_TOP             
  
    3           7 LOAD_CONST               1 ('')
               10 PRINT_ITEM          
               11 PRINT_NEWLINE       
               12 JUMP_FORWARD             1 (to 16)
          &gt;&gt;   15 POP_TOP             
          &gt;&gt;   16 LOAD_CONST               0 (None)
               19 RETURN_VALUE    
  </code></pre>
  <p>And the JUMP_ABSOLUTE will appear if the IF statement is at the end of another loop. For instance:</p>
  <pre><code>&gt;&gt;&gt; def f1():
      if a:
          if b:
              print ''
  &gt;&gt;&gt; dis(f1)
    2           0 LOAD_GLOBAL              0 (a)
                3 JUMP_IF_FALSE           20 (to 26)
                6 POP_TOP             
  
    3           7 LOAD_GLOBAL              1 (b)
               10 JUMP_IF_FALSE            9 (to 22)
               13 POP_TOP             
  
    4          14 LOAD_CONST               1 ('')
               17 PRINT_ITEM          
               18 PRINT_NEWLINE       
               19 JUMP_ABSOLUTE           27
          &gt;&gt;   22 POP_TOP             
               23 JUMP_FORWARD             1 (to 27)
          &gt;&gt;   26 POP_TOP             
          &gt;&gt;   27 LOAD_CONST               0 (None)
               30 RETURN_VALUE        
  </code></pre>
  <p>From the Bytecode I am reading to write back the code, there is a JUMP_ABSOLUTE that surprises me:</p>
  <pre><code>121         228 LOAD_FAST               11 (a)
              231 LOAD_CONST               9 (100)
              234 COMPARE_OP               0 (&lt;)
              237 JUMP_IF_FALSE           23 (to 263)
              240 POP_TOP             
              241 LOAD_FAST               11 (b)
              244 LOAD_CONST              11 (10)
              247 COMPARE_OP               4 (&gt;)
              250 JUMP_IF_FALSE           10 (to 263)
              253 POP_TOP             
  
  122         254 LOAD_CONST               3 (1)
              257 STORE_FAST               4 (ok)
              260 JUMP_ABSOLUTE           27
          &gt;&gt;  263 POP_TOP      
  </code></pre>
  <p>I would think the code is the following:</p>
  <pre><code>if a&lt;100 and b&gt;10:
              ok=1
  </code></pre>
  <p>but it provokes a JUMP_FORWARD and not a JUMP_ABSOLUTE. I know it is not a WHILE loop, nor a FOR statement because they both create a SETUP_LOOP line in the Bytecode.</p>
  <p>My question is: what am I missing ? why do I get a FORWARD instead of ABSOLUTE jump ?</p>
  <p>EDIT: The absolute jump to index 27 points to the beginning of a (WHILE?) loop in which these two lines 121 and 122 belong to:</p>
  <pre><code>106          24 SETUP_LOOP             297 (to 324)
          &gt;&gt;   27 LOAD_FAST                4 (ok)
               30 LOAD_CONST               1 (0)
               33 COMPARE_OP               2 (==)
               36 JUMP_IF_FALSE          283 (to 322)
               39 POP_TOP   
  
        
  </code></pre>
  <p>There is an IF-statement before and another one after these lines. Here is the code before, with the same JUMP_ABSOLUTE closing the statement.</p>
  <pre><code>115         170 LOAD_FAST                3 (q)
              173 LOAD_CONST              10 (1)
              176 COMPARE_OP               0 (&lt;)
              179 JUMP_IF_FALSE           45 (to 227)
              182 POP_TOP             
              183 LOAD_FAST               11 (z)
              186 LOAD_CONST              11 (10)
              189 COMPARE_OP               4 (&gt;)
              192 JUMP_IF_FALSE           32 (to 227)
              195 POP_TOP             
  
  116         196 LOAD_CONST               1 (0)
              199 STORE_FAST               4 (ok)
  
  117         202 LOAD_FAST                5 (u)
              205 LOAD_CONST               3 (1)
              208 BINARY_ADD          
              209 STORE_FAST               5 (u)
  
  118         212 LOAD_CONST               1 (0)
              215 STORE_FAST               3 (k)
  
  119         218 LOAD_CONST               3 (10)
              221 STORE_FAST               6 (dv)
              224 JUMP_ABSOLUTE           27
          &gt;&gt;  227 POP_TOP             
  </code></pre>
  <p>The JUMP_FORWARD says &quot;go to the next line&quot; and the JUMP_ABSOLUTE says &quot;go back to the beginning of the WHILE loop&quot;. Problem is I don't know how to replicate a code that would give the same bytecode as above.</p>
  <p>Thank you !</p>