title: Python: Range for loop. Do something different every 5
body: <p>I am writing a script for Nuke to arrange selected nodes in a grid. Every node has x and y coordinates. This script alters those coordinates. I would like to have the grid have a horizontal length of 5 and then start a new line. I have this written in a range loop. The range is determined by the number of selected nodes. I have multiple if statements that drop the nodes to a new line. My question is if there is a way to clean up the if statements to be less literal and not have to be reiterated every 5 times. Here is the script:</p>
  
  <pre><code>list = []
  for s in nuke.selectedNodes():
      n = s['name'].value()
      list.append(n)
  names = iter(list)
  
  c = len(nuke.selectedNodes())
  
  for i in range(c):
  
      xNumber = i*200
      yNumber = 0 
  
      n = i+1
  
      if n &gt; 5:
          xNumber =  (i-5)*200
          yNumber = 200
      if n &gt; 10: 
          xNumber = (i-10) *200
          yNumber = 400
      if n &gt; 15:
          xNumber =  (i-15)*200
          yNumber = 600
      if n &gt; 20: 
          xNumber = (i-20)*200
          yNumber = 800
      if n &gt; 25:
          xNumber =  (i-25)*200
          yNumber = 1000
      if n &gt; 30: 
          xNumber = (i-30) *200
          yNumber = 1200
      if n &gt; 35:
          xNumber =  (i-35)*200
          yNumber = 1400
      if n &gt; 40: 
          xNumber = (i-40)*200
          yNumber = 1600
      if n &gt; 45:
          xNumber =  (i-45)*200
          yNumber = 1800
      if n &gt; 50: 
          xNumber = (i-50)*200
          yNumber = 2000
      if n &gt; 55:
          xNumber =  (i-55)*200
          yNumber = 2200
      if n &gt; 60: 
          xNumber = (i-60) *200
          yNumber = 2400
      if n &gt; 65:
          xNumber =  (i-65)*200
          yNumber = 2600
      if n &gt; 70: 
          xNumber = (i-70)*200
          yNumber = 2800
      if n &gt; 75:
          xNumber =  (i-75)*200
          yNumber = 3000
      if n &gt; 80: 
          xNumber = (i-80) *200
          yNumber = 3200
      if n &gt; 85:
          xNumber =  (i-85)*200
          yNumber = 3400
      if n &gt; 90: 
          xNumber = (i-90)*200
          yNumber = 3600
      if n &gt; 95:
          xNumber =  (i-95)*200
          yNumber = 3800
      if n &gt; 100: 
          xNumber = (i-100)*200
          yNumber = 4000
  
      NodeName = next(names)
  
      nuke.toNode(NodeName)['xpos'].setValue(xNumber)
      nuke.toNode(NodeName)['ypos'].setValue(yNumber)
  </code></pre>
  
  <p>The script works, I just feel like there should be a cleaner way to write this.</p>