Dumb'n'Noobie question: Switch into While

Hello, World! (no offence!)

I'm studying C++11 from the Stroustrup but I have already study the C, then I know the basics of this type of programming languages (no offence again!).

I have this very simple code with a Switch into a While:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>
using namespace std;

int main()
{
    int tries=1;
    while (tries<4) {
        cout << "Do you want to procees (y or n)?\n";
        char answer = 0;
        cin >> answer;
        
        switch (answer) {
                case 'y':
                    return true;
                case 'n':
                    return false;
                default:
                    cout << "Sorry, I don't understand that.\n";
                ++tries;
                
        }
        
        }
    cout << "I'll take it for a no\n";
    return false;
}

It works (of course)! But my logic imposes me a question: If I put 'y' or 'n' like answer, why the program ends if "tries" is less than 4?

Thank you very much for your answers and sorry for my stupid question.
Last edited on
If answer is 'y' or 'n', we return from main() (lines 14, 16)
Returning from main() ends the program.
That's Right. Thank you :)
Topic archived. No new replies allowed.