Question about bool and a loops in it

hello, sorry i'm a beginner to c++ programming so i don't really understand everything clearly. i've made a bool function and in it i have an if statement where if it works, i return true.

my question is, if i say else and return false, will the program take me out of the bool function or will it allow me to go into the for loop i have following the if/else statement?

for example:
// assuming strings and everything have been declared
if (string.size() == 0)
return true;
else
return false;
for (int m = 0; m != string.size; m++)
{ ......
}

will the return false still allow me to continue on with the for loop even if the for loop has a string size larger than 0?

apologizes in advance if this isn't clear, i'm having a hard time putting everything into words . thank you!
return transfers control back to the caller immediately, so if both branches of an if statement end in a return statement, nothing after the if will execute.
The following are all equivalent:
1
2
3
4
5
6
7
8
9
if (/*...*/){
    //true code
    return /*...*/;
}else{
    //false code
    return /*...*/;
}
//other code
//(end of function scope) 

1
2
3
4
5
6
7
8
if (/*...*/){
    //true code
    return /*...*/;
}
//false code
return /*...*/;
//other code
//(end of function scope) 

1
2
3
4
5
6
7
if (/*...*/){
    //true code
    return /*...*/;
}
//false code
return /*...*/;
//(end of function scope) 
Last edited on
Topic archived. No new replies allowed.