title: How break method execution in the TypeScript
body: <p>I have easy problem. I have method <code>setProductCart</code> and I have <code>for</code> loop and in for I have <code>if</code> condition and when I execute the condition I want to back out from method. I using <code>return</code> for that, but I am not sure that is correct. </p>
  
  <pre><code>setProductCart(product: ProductModel) {
  
          for (let i = 0; i &lt; this.productCart.length; i++) {
              if (product.name == this.productCart[i].name) {
  
                  this.productCart[i].price += product.price;
                  this.productCart[i].numberOfProduct += 1;
                  return;
  
  
              }
          }
          this.productCart.push(product);
          this.shopCartChanged.next(this.productCart);
  
      }
  </code></pre>
  
  <p>Does anyone know bather solution for this?</p>