C ++ do while 0 usage and significance, dowhile
/* Usage and significance of do while 0 * // recently, do while 0 has been seen in many codes. At first glance, didn't this do anything? Why. Is that an alternative? Of course not. // 1.0 help define complex macros to avoid errors when referencing: // suppose you want to define a macro like this # define DOSOMETHING () \ func1 (); \ func2 (); // call int a = 3; if (a> 3) DOSOMETHING () // expand if (a> 3) func1 (); func2 (); // no matter how fun2 is executed. // if it is wrapped up, it should be like this when it is expanded. if (a> 3) // both functions can be executed to do {func1 (); func2 () ;}while (0); // 2.0 avoid using goto to control the Program Stream uniformly: do {int * I = new int (); if (I = func1 () {break;} if (I = func2 () {break ;}} while (0); // 3.0 avoid empty macros caused by warning // due to different architecture constraints in the kernel, empty macros are often used. during compilation, the empty Macro will provide a warning. To avoid such a warning, you can use do {} while (0) to define the empty macro: # define EMPTYMICRO do {} while (0)
Meaning of an example of dowhile (0)
Avoid using goto.
In the past, the traditional practice of c was to use goto to handle exceptions. However, goto is not easy to manage. So we replaced it with while (0 ).
Logic in C language or usage in dowhile
I don't know what you are talking about. First you enter-1, the screen prints-1, and then judge that a <0 is true and continues to run. If you input 2, the screen prints 2, then judge that a is not true and the program ends.