'do while' or recursion on a switch? [duplicate]

0

I have 2 models of code here, please note:

Template 1 (using 'do while'):

int main(){

    char opc;

    do{

        std::cout << "|============|\n";
        std::cout << "|Escrever.[1]|\n";
        std::cout << "|Ler......[2]|\n";
        std::cout << "|============|\n\n";
        std::cout << "Oque deseja fazer?";
        std::cin >> opc;

        std::cin.ignore();
        system("cls");

        switch(opc){

            case '1':

                escreve();

            case '2':

                leitura();

            default:

                std::cout << "Opção incorreta!\n\n";
        }

    }while(opc!='1' || opc!='2');

    return 0;
}

Template 2 (using recursion):

int main(){

    char opc;

    std::cout << "|============|\n";
    std::cout << "|Escrever.[1]|\n";
    std::cout << "|Ler......[2]|\n";
    std::cout << "|============|\n\n";
    std::cout << "Oque deseja fazer?";
    std::cin >> opc;

    std::cin.ignore();
    system("cls");

    switch(opc){

        case '1':

            escreve();

        case '2':

            leitura();

        default:

            std::cout << "Opção incorreta!\n\n";
            main();
    }

    return 0;
}

Doubt: Which of the two would be the ideal one to use?

    
asked by anonymous 01.02.2018 / 03:39

0 answers