title: SwiftUI Error: "Closure containing control flow statement cannot be used with function builder 'ViewBuilder'"
body: <p>I tried a SwiftUI tutorial, &quot;Handling User Input&quot;.</p>
  <p><a href="https://developer.apple.com/tutorials/swiftui/handling-user-input" rel="nofollow noreferrer">https://developer.apple.com/tutorials/swiftui/handling-user-input</a></p>
  <p>I tried implementing it with <code>for</code> instead of <code>ForEach</code>.
  But an error arose: &quot;Closure containing control flow statement cannot be used with function builder 'ViewBuilder'&quot;.</p>
  <p>FROM:</p>
  <pre><code>import SwiftUI
  
  struct LandmarkList: View {
      @State var showFavoritesOnly = true
      
      var body: some View {
          NavigationView{
              List{
                  Toggle(isOn: $showFavoritesOnly){
                      Text(&quot;Show FavatiteOnly&quot;)
                  }
                  
                  ForEach(landmarkData) { landmark in
                      if !self.showFavoritesOnly || landmark.isFavorite {
                              NavigationLink(destination: LandmarkDetail(landmark: landmark)) {
                                  LandmarkRow(landmark: landmark)
                              }
                          }
                  }
              }
              .navigationBarTitle(Text(&quot;Landmarks&quot;))
          }
      }
  }
  </code></pre>
  <p>TO (I wrote):</p>
  <pre><code>import SwiftUI
  
  struct LandmarkList: View {
      @State var showFavoritesOnly = true
      
      var body: some View {
          NavigationView{
              List{
                  Toggle(isOn: $showFavoritesOnly){
                      Text(&quot;Show FavatiteOnly&quot;)
                  }
                  
                  for landmark in landmarkData {
                      if $showFavoritesOnly || landmark.isFavorite {
                          NavigationLink(destination: LandmarkDetail(landmark: landmark)){
                              LandmarkRow(landmark: landmark)}
                          }
                  }
              }
              .navigationBarTitle(Text(&quot;Landmarks&quot;))
          }
      }
  }
  </code></pre>