Angular: Value stored in variable in subscribe cannot be used outside subscribe [duplicate]

I have a component that will show all the questions received from the GET request. The problem is when the service is called in the components OnInit method after storing the response from the subscribe in a variable that variable can’t be used anywhere else. Let me give my code below for understanding:

Service

getQuestions():Observable<any> {
    return this.http.get<any>(this.url + '/getQuestions');
}

Component.ts

ngOnInit() {
    this.appService.getQuestions().subscribe(response => {
      this.response = response.questionCategories;
    });
    console.log(this.response);
    for (let i = 0; i < this.response[this.subject_id].sections.length; i++) {
      this.totQus = this.response[this.subject_id].sections[i].questions.length + this.totQus;
    }
  }

Problem is here in Subscribe I’ve stored the value in this. response but when I log it in the console it is showing ‘undefined’. For this, the loop is also not running. But if I keep the loop inside subscribe the totQus value will be 0 outside subscribe which will also create a problem for me.

Is there anything am missing?
Please help me.

Source: New feed
Source Url Angular: Value stored in variable in subscribe cannot be used outside subscribe [duplicate]