---- Editorial:
On the contrary, Jon, getting out of loops early--without using goto--is exactly the original purpose of break. The use in switch() is simply keyword economy. A testament to this is the existence of "continue", which has no meaning in a switch block. The idea behind break, continue and return is that that they are all "limited forward goto" operations tied to the structure of the program rather than arbitrarily-placed labels. Just like with if/else.
PS: I approve of not using break or continue (or return!) mindlessly, and I'm aware of structured programming ideas going back to before my time, from Dijkstra, Wirth, Hoare and others.
PPS: I wasn't one of the TD issuers.
---- End OpEd Mode
It's hard to tell what's going on in this program. You call indexOfKey() twice at the top of the loop, only capturing the return value on the second call. That's weird enough to deserve a comment or two.
You don't know keyNumber getting set to anything before, or during, the loop. It could be set as a reference argument in indexOfKey(), but without seeing at least a prototype how is anyone going to guess that.
Take a long think about this. When you enter that loop, you will loop forever if nothing sets keyNumber to zero. Maybe you need some additional condition, along the lines of what Jon was suggesting,
Just from what I see, it looks like you are getting key numbers from some source, accidentally left an extra indexOfKey call in the loop, and forgot to get the next key number (with 0 indicating that there aren't any more) at the bottom of the loop. If it's from console input, maybe add:
cout << "Enter next key, or 0 to end: ";
cin >> keyNumber;
...just before the closing brace, and things might be better. If you're stepping through a list of keys in an array or collection, then a for() loop might be more appropriate. From a file, don't prompt, just:
keyin>>keyNumber;
if (!keyin) // stop on eof or error
{ keyNumber = 0; }
...or something like that, instead.