In C why do you need a statement after a goto label?

前端 未结 3 1166

I am writing some C code and in my code I have two nested loops. On a particular condition I want to break out of the inner loop and continue the o

3条回答
  •  情歌与酒
    2020-12-11 00:16

    You simply need to write:

    label: ;
    

    The semi-colon is an empty statement. You need it because the language is defined like that; you need to go to a statement, even if it is an empty one.

        for (int i = 0; i < N; i++)
        {
            for (int j = 0; i < M; j++)
            {
                ...
                if (some_condition)
                    goto continue_loop1;
                ...
            }
    continue_loop1: ;
        }
    

    You can argue about the indentation on the label.

提交回复
热议问题