Invalid token 'while' in class, struct, or interface member declaration in very simple code

后端 未结 5 543
你的背包
你的背包 2021-01-02 17:57

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,

5条回答
  •  礼貌的吻别
    2021-01-02 18:25

    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.

提交回复
热议问题