if statement inside while loop

The solution in this case: scour your code and find the extraneous } which can be lots of lines before where the error is thrown, literally hundreds of lines, this kind of errors can be hard to find. Doing a Ctrl-T helps a lot, it fixes your indentation and that in turn helps you to find where the offending block is.

To understand error messages, make sure you understand C++ syntax, as in fact the error message does tell you pretty much what's wrong: something with the } token, and you should know you must have the { and } tokens balanced.