In two different ways i wrote a method. one makes use of recursion and the 
other a infinite loop.
Though I personally prefer the infinite loop,  but i got to know that the 
recursive type was inefficient, memory wise.


I read some comment about it. Someone wrote: "To iterate is human, to recurse: 
devine"and another site said, on fibonacci() ,
WARNING:When you run this program,   use a small number (less than 15).
 Because this uses recursion, it can consume   a lot of memory. 

So that left me wondering if recursion is in same category as "goto" , "know 
it, but don't use it".
 or are there some instance or some way where they can be used effeciently, 
like in my case?

//the recursive type
void ask_stuId(){
        string userInput;
        cout<<"Enter your full student Id"<<endl;
        getline(cin,userInput);
        if(isMatch_strFormat(userInput,"aaa/####/###"))
            stuId=userInput;
        else {
            cout<<"In correct format, ";
            ask_stuId();
        }
    }



//the infinite loop
void ask_stuId(){ 
    string userInput;
    cout<<"Enter your full student Id"<<endl;
    while(1)
    {
        getline(cin,userInput);
        if(isMatch_strFormat(userInput,"aaa/####/###")){
        stuId=userInput;
        break;
        }  

        else cout<<"Please enter id in correct format"<<endl;
    }

}

thanks all
Lawal. O



      

[Non-text portions of this message have been removed]

Reply via email to