I was personally wondering why in most of the example functions, there is the searching code which breaks out of the loop, and then after the loop, it gets tested as to whether it should return or not. Namely:
That is the first example. Is there a benefit to writing the code this way? I would think it would be best to just return immediately from the loop, as then you don't have to do extra testing at the end.....correct me if I'm wrong here. It could very possibly be just for readability-sake.Code:for ( i = 0; i < size; i++ ) { if ( key == list[i] ) break; } if ( i < size ) { found = true; rec = &list[i]; }