![Thames & Kosmos Code Gamer Скачать руководство пользователя страница 60](http://html1.mh-extra.com/html/thames-and-kosmos/code-gamer/code-gamer_experiment-manual_1099224060.webp)
Let’s take a simple example:
It could be written as follows:
Or — even worse — as follows:
if (digitalRead(button1) == LOW
) {
red = 255;
} else {
red = 0;
}
if (digitalRead(button1) == LOW
) {
red = 255;
} else {
red = 0;
}
if (digitalRead(button1) == LOW
) {red = 255;} else
{red = 0;}
Indented
You may have wondered why a lot of the l
ines found in
the programming text are indented, or mo
ved a little to
the right compared to the others. The reas
on for it is
simple: It makes the programming text ea
sier to read.
All these versions mean the same thing, it
’s just the
formatting that changes. And yet, in the f
irst example
you can see the structure of the program a
t a glance. It
is easier to read the code.
That is why it makes sense to indent the p
rogram code
whenever it begins a new block. Also, as a r
ule, each
individual instruction should get its own l
ine.
The Arduino environment will help you w
ith this, and
usually moves new blocks to the right all b
y itself. If
you ever want to indent portions of text b
y hand,
though, use the tab key rather than the sp
ace key.
◀
Automatic formatting
KNOWLEDGE BASE
58
CodeGamer manual inside english.indd 58
7/19/16 12:33 PM