I am not sure what the problem is but I keep receiving this error when I try to use a while statement in my code.
Invalid token \'while\' in class,
Based on the error, it sounds like the compiler thinks this code is typed directly in the body of a class/struct/interface declaration. Statements while/if/for/etc ... must appear with in a method.
Try moving this code into a method to fix the problem. If it's in a method, you likely have a mismatched brace problem.