Wednesday, December 15, 2010

【School】 SCM weak c language tutorial --- Lesson: Statement (1) - expression statement】.

<br> lessons from the fourth to the seventh class, learn the most basic grammar, this lesson was to learn the syntax of basic statements can be said that the soul of the composition process. .In the previous example in the curriculum, but also simple to understand the usage of some statements, we can see that C language is a structured programming language. .C language provides a wealth of program control statements. .Study and master the use of these statements is the focus of C Language Learning. .<BR> Expression statement is the most basic kind of statement. .Different programming languages will have different expression statements, such as VB is joined in the expression carriage return to form after VB's expression statement, and in the C language in the 51 SCM is add a semicolon ";" constitutes .expression statement. .Examples are as follows: <BR> b = b * 10; <BR> Count + +; <BR> X = A; Y = B; <BR> Page = (a + b) / a-1; <BR> <BR> more .are a legitimate expression statement. .I received some of the users in the Email, we found that beginners tend to write and debug procedures friends ignored the semicolon ";" caused by the normal criminal procedure compiled. .My personal experience is the first time in the face of compile error syntax is wrong, which beginners often joined in the program because of the whole angle of symbols, the wrong operator followed by missing or not ";." .<BR> In the C language has a special expression statement, called the empty statement, it is only by a semicolon ";" component. .Sometimes in order to make the syntax is correct, then it requires a statement, but this statement has no practical effect of it when she has to run an empty statement. .As you said it when the late self-taught as with bag holder, huh, huh. .<BR> Empty statement will usually use the following two. .<BR> <BR> (1) while, for loop composition followed by a semicolon, do not perform other operations to form an empty loop. .I will often wait to use it to write event procedures. .We have to note that ";" was used as a null statement, and statement to be an effective part of the semicolon to distinguish, such as for (; a <50000; a + +); the first by a semicolon should be regarded as an empty statement, it .make a assigned to 0 (but note that the value of such a program before, then a, is a current value of the initial value), a semicolon is the last line of the entire statement into an empty circle. .So for (; a <50000; a + +); equivalent for (a = 0; a <50000; a + +); I used to write the back is written, so that can make people more likely to read to understand. .<BR> <BR> (2) the relevant statements in the program provide for the label, marking the location of program execution, so that the relevant statement to jump to the location to be executed. .This will be used in goto statements. .<BR> The following example program is a simple statement that while the use of space. .The function of the hardware is simply a switch are connected to the P3.7, P1 when the switch is pressed, all the lamps light up on. .Of course, the practical application of the function keys, and not so simple to achieve, often have to be anti-shake processing. .In our first experiment <BR> board plus a button. .Circuit shown in Figure 8-1. .Add a button <BR> Figure 8-1 Experimental schematic <BR> procedures are as follows: <BR> # include <AT89x51.h> void main (void) <BR> {<BR> unsigned int a; <BR> do .<BR> {<BR> P1 = 0xFF; / / close the P1 on the LED <BR> while (P3_7); / / empty statement, waiting P3_7 press for the low, low, the following statement <BR> .P1 = 0; / / lit LED <BR> for (; a <60000; a + +); / / This is an empty statement usage, pay attention to the initial value for the current value of a <BR>} / / This first press .There will be a light delay time, how long to light long after the press <BR> while (1); / / light off again after a period of time to judge P3_7, so the cycle <BR>} <BR>.

No comments:

Post a Comment