title: Avoid three for-in loops to compute values
body: <p>Supposed I have these objects which are nested :</p>
  <pre><code>struct Order {
      let ref: Int
      let starters: [Starter]
      let formatedDate: String
      var status: Int?
  }
  
  struct Starter {
      let subEntries: [SubEntry]
  }
  
  struct SubEntry {
      let status: Int
      let id_Dish: Int
  }
  </code></pre>
  <p>I need to make some operations to filter some elements and at this moment I only manage to make it by using 3 for in loops as below :</p>
  <pre><code>func computeStatus(openOrders: inout [Order]) {
      for openOrder in openOrders {
          for entry in openOrder.starters {
              outerLoop: for subEntry in entry.subEntries {
                  if subEntry.id_Dish == 0 {
                      print(&quot;\(openOrder.ref) is canceled&quot;)
                      break outerLoop
                  }
                  if !entry.subEntries.filter({ $0.status &lt; 16 }).isEmpty {
                      print(&quot;\(openOrder.ref) is waiting&quot;)
                      break outerLoop
                  } // waiting
                  if entry.subEntries.filter({ $0.status == 0 }).isEmpty &amp;&amp; entry.subEntries.filter({ $0.status == 16}).count &gt;= 1  {
                      print(&quot;\(openOrder.ref) is in production&quot;)
                      break outerLoop
                  }
                  if entry.subEntries.allSatisfy({$0.status == 255 }) {
                      print(&quot;\(openOrder.ref) is ready&quot;)
                      break outerLoop
                  }
              }
          }
      }
  }
  </code></pre>
  <p>How can I refactor this code and avoid the multiple loops ?</p>