Page 61 - Programming Microcontrollers in C
P. 61

46     Chapter 1  Introduction to C

                          nu=nu+1;
                       else
                          nother=nother+1;
                          This single statement has quite a few lines of code associated with it,
                          and there are some new concepts here. First, the arguments of the ifs
                          are combinations of two logical expressions. The expression
                   c==’A’ || c==’a’

                          says that if c is equal to uppercase a OR if c is equal to lowercase
                          a the argument is TRUE. The vertical bars || are the logical opera­
                          tor OR.
                              The first if statement is evaluated. If its argument is TRUE, the
                          statement following the if is executed and program control moves
                          to the end of the if statements. Otherwise, the first else if state­
                          ment argument is evaluated. If this argument is TRUE, the following
                          statement is executed and program control moves to the end of the
                          if statements. This process is repeated until one of the arguments is
                          found to be TRUE, or all of the else if statements are evaluated.
                          At that time, the final statement following the else entry is evalu­
                          ated. The final else is not required.
                              In the above statement, please note that the while statement
                          itself and all that follows it form a single statement to the compiler.
                          Likewise, the combination of all of the if-if else constructs
                          also form a single statement. Furthermore, each of the statements
                          following either an if or an if else form single statements. The
                          formatting of this statement helps you understand what is going on,
                          but remember, the format of such a statement is completely up to the
                          programmer. The language is completely free format. The while
                          statement above and its statement following is indeed confusing to
                          observe, and probably the one thing that the programmer can do to
                          reduce the confusion is to block the statements following both the
                          while and the if and else key words. In this case the while
                          statement would look like

                   while ((c=getchar())!=EOF)
                   {
                       if(c==’A’ || c==’a’*
                       {
   56   57   58   59   60   61   62   63   64   65   66