1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Return values in while loops in functions.

  1. Mar 1, 2010 #1
    1. The problem statement, all variables and given/known data I'm just trying to interpert how the return statement works.

    bool check(int item, vector<int>& v2)
    { int i = 0;
    while (i < v2.size())
    { if (item == v2)
    return true;
    }return false;
    2. Relevant equations

    3. The attempt at a solution

    I'm confused about the return parts of this problem. I does the return false even get excecuted? I thought that once a return statement is reached in a function, the function exits. Or do I have to wait until the last "true" return for the function to exit?
  2. jcsd
  3. Mar 1, 2010 #2
    Think about the control flow of the code. The return true follows an if statement, so what does that mean? If that if conditional doesn't evaluate to true, what happens?
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook