title: How to have a dynamic List of Views using SwiftUI
body: <p>I can do a static List like</p>
  
  <pre><code>List {
     View1()
     View2()
  }
  </code></pre>
  
  <p>But how do i make a dynamic list of elements from an array?
  I tried the following but got error: <strong>Closure containing control flow statement cannot be used with function builder 'ViewBuilder'</strong></p>
  
  <pre><code>    let elements: [Any] = [View1.self, View2.self]
  
      List {
         ForEach(0..&lt;elements.count) { index in
            if let _ = elements[index] as? View1 {
               View1()
            } else {
               View2()
            }
      }
  }
  </code></pre>
  
  <p>Is there any work around for this?
  What I am trying to accomplish is a List contaning dynamic set of elements that are not statically entered.</p>