title: Is there a way to work around using a break statement?
body: <p>I have a working binary search function that asks a to user input a name and it will search for it in the Student array structure and display the corresponding average GPA for that student. It will keep looping for the user to enter in a name to search for unless the user enters in a period. </p>
  
  <p>The problem I have is the <code>break</code> statement I am using. The requirements for this function that I need to follow does not allow me to use a <code>break</code> statement. </p>
  
  <p>However, if I remove the <code>break</code> statement, my binary search will infinitely print out the output statement and will not work properly anymore. </p>
  
  <p>Is there a way for me to work around this and not use a <code>break</code> statement? I have a feeling I could be using several <code>if</code> statements instead of the <code>break</code> statement.</p>
  
  <pre><code>void binarySearch(Student* ptr, int MAXSIZE)
  {
     string target;
     string period = ".";
  
     int first = 0,
     last = MAXSIZE - 1,
     mid;
  
    do
    {
      cout &lt;&lt; "Enter student name (Enter . to stop): ";
      cin  &gt;&gt; target;
  
      while (first &lt;= last)
      {
          mid = (first + last) / 2;
          if (ptr[mid].name.compare(target) == 0)
          {
              cout &lt;&lt; "Student " &lt;&lt; target &lt;&lt; " :gpa " &lt;&lt; ptr[mid].avg &lt;&lt; endl;
              first = 0;
              last = MAXSIZE - 1;
              break; // I am stuck on making the binary search work without using this break statement
          }
          else if (ptr[mid].name.compare(target) &lt; 0)
              last = mid - 1;
          else
              first = mid + 1;
      }
      if (first &gt; last &amp;&amp; target.compare(period) != 0)
      {
          cout &lt;&lt; "This student was not found. Enter another name" &lt;&lt; endl;
          first = 0;
          last = MAXSIZE - 1;
      }
    } while (target.compare(period) != 0);
  }
  </code></pre>