9 programming habits of successful software developers (3)

zhaozj2021-02-17  52

4. Some people who do not mess with the IF statement like to use the "if" statement, as follows: if (a == 0) {A ; return (a);} if (a == 1) {a = 5; return (A );} if (a == 2) {a = 10; return (a);} if (a == 3) {a = 20; return (a);} if (a == 4) EXIT ( 1) Is there any better way than this? ELSE IF statement? Not. A good way is to write a simple program with the "switch-case" statement: Switch (a) {case 0: A ; return (a); case 1: a = 5; return (a); case 2: a = 10; Return (a); case 3: a = 20; return (a); default: exit (1);} If the value is not consistent with A, the job defined in Default is executed, the above example is to Perform the end.

转载请注明原文地址:https://www.9cbs.com/read-29469.html

New Post(0)