Page 68 - Programming the Photon Getting Started With the Internet of Things
P. 68

The multiline comment is separated by /* and */. You can use this at the start of your
               program to introduce the code and write a short description of what your program
               does.


             The following example shows both types of commenting syntax:


        /* This is an example of how to write different types of comments with your

         program.
        Written by Christopher Rush
        */
        void loop() {
                   int count = 0;

                   count ++; //adds plus one to the integer count
                   if (count == 10) {
                              count = 0;

                              delay(1000) //pauses for 1 second
                   }
        }


             In this book I will stick to using single-line comments, usually to help explain what is
        happening in the code. It is useful if other people are going to use the code or snippets of
        the code in their projects. Sometimes it can be confusing for the beginner knowing when
        and when not to use comments; however, I usually follow a few simple rules that should

        make things a bit easier. Comments should be used to


               Explain anything that can be a little tricky to comprehend
               Describe something the user may need to do that is not written in the code; for

               example, //LED must be wired up to pin D1
               Leave yourself notes or instructions: // Note: tidy up this code with an easy function


             The last point can be very useful to use either Note or Todo, which reminds you that

        you need to come back to this point sometime in the future. Some IDE compilers allow
        you to search for keywords.





        Whitespaces



        The compiler program will always ignore any whitespace lines in your program, unless
        they are spaces that separate words in your code—that is, the following code will still
        work, but reading it or debugging would prove to be very difficult:


        void loop() {int
        count = 0; count ++; if(
   63   64   65   66   67   68   69   70   71   72   73