title: Dart: Exit a function from if within a foreach loop
body: <p>I want to break the function after the <code>if</code> statement, but I unable to do so.</p>
  
  <p>Below is my code snippet.</p>
  
  <blockquote>
  <pre><code>void addOrderToCart(Product product, int quantity, String color, String size) {
      _lastOrder = Order(product, quantity, _orderId++, color, size);
  
      _orders.forEach((element) {
        if(element.product.id == _lastOrder.product.id){
         element.colors.add(color);
         element.sizes.add(size);
         element.quantity = element.quantity + quantity;
         notifyListeners();
         return;
        }
      });
      _orders.add(_lastOrder);
      notifyListeners();
    }
  </code></pre>
  </blockquote>
  
  <p>Thanks.</p>