9 programming habits of successful software developers 4

zhaozj2021-02-08  215

5. Many people who do not mess with the procedure (Block) often use the program to cut off. It is a program that is more difficult to understand using more than three cut off. Please see the example below:

INT A = 10;

INT b = 20;

INT C = 30;

INT D = 40;

IF (a == 10)

{

A = a D;

IF (b == 20)

{

B = B A;

IF (c! = b)

{

C = C 1;

IF (D> (A B))

Printf ("Made It All the Way To The Bottom! / N");

}

}

}

This may be exaggerated, but there are still many people really do. How do you write better? One way is to use a function to write:

Void next (int A, int B, INT C, INT D)

{

IF (c! = b)

{

C = C 1;

IF (D> (A B))

Printf ("Made It All the Way To The Bottom! / N");

}

}

int main ()

{

INT A = 10;

INT b = 20;

INT C = 30;

INT D = 40;

IF (a == 10)

{

A = a D;

IF (b == 20)

{

B = B A;

NEXT (A, B, C, D);

}

}

Return (0);

}

To write this, you may increase the workload, but the program is structured, it is easy to understand, and if the function is better, you can use it elsewhere.

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

New Post(0)