title: Typescript boolean function must return a value
body: <p>I have following Typescript boolean function:</p>
  
  <pre><code>checkRiskValues(): boolean {
      this.controlsName.forEach((item) =&gt; {
          this.threatForm.get(item)!.valueChanges.subscribe(value =&gt; {
              this.valueControlArray.push(this.threatForm.get(item)!.value);
  
              if (this.valueControlArray.indexOf(true) &gt; -1)
                  return true;
  
              else
                  return false
          });
      });
  }
  </code></pre>
  
  <p>The method appears error the function must return value. I know it, but I'm not sure how to implement this true/false statement outside foreach scope ?</p>
  
  <p>If I call if/else statament outside foreach loop result is always false because     </p>
  
  <pre><code>if (this.valueControlArray.indexOf(true) &gt; -1)
  </code></pre>
  
  <p>is empty..</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I've deleted checkRiskValues() function and add complete logic in ngOnInit() method and I'have also added valueControl varibable that keep true/false value and pass in another function. Thanks everyone..This my solution:</p>
  
  <pre><code>ngOnInit() {
      this.controlsName.forEach((item) =&gt; {
          this.threatForm.get(item)!.valueChanges.subscribe(value =&gt; {
              this.valueControlArray.push(this.threatForm.get(item)!.value);
  
              if (this.valueControlArray.indexOf(true) &gt; -1) {
                  this.valueControl = true;
  
              }
              else {
                  this.valueControl = false;
              }
          });
      });
  }
  </code></pre>