vendredi 23 juin 2017

I can't understand break statement in function?

i write a function where there aren't return statement but there are break statement in while loop .. why when the condition is true,the break statment return value(5(key in programm))

int breakStatement(){
        while(true){
            char value = 'n';
            int key = 5;
            cout << "inter Value : ";
            cin >> value;  // we suppose that user enter the value equals 'n'
            cout << "inter key : ";
            cin >> key;  // we suppose that user enter the key equals 5
            if(value == 'n' && key ==5 )
                break;
      }
 }

int main() {
        int value = breakStatement();
        cout << value;  // the value equals 5
        return 0;
    }

Aucun commentaire:

Enregistrer un commentaire