Q:

Break for loop with function?

void fbreak(int i){
   if(5==i)
      break;
}
void main(){
   for(int i = 0;i<10;i++){
      fbreak(i);
   }
}

I want to function fbreak break for loop. But it seems that my code does not work.

A:

In fact what you are trying to do is to implement stadard algorithm std::find (or std::find_if) declared in header <algorithm>
You could write your program the following way
bool fbreak( int i )
{
   return i == 6;
}

int main()
{
   int i = 0;

   while ( i < 10 && !fbreak( i ) ) i++;
}

Take into account that function main shall have return type int.

