Back to: Developing Distributed Environmental Sensors
Key Things
- open a bracket or quote, it must be closed
- a block of code is stuff to be done one step at a time, but can be separated from other blocks of code
- e.g. to separate commands to be executed if a test is positive vs if it is negative
- blocks of code are indicated by
{ <code stuff> }
- most lines need to end with a
;
(except at the end of blocks- e.g. no semi-colon after a}
) - there are some special language keywords that are instructions/commands; you can not use these words for variable names
- see this list
- variables are named bits of memory that you can store (remember) some piece of info
- variable names can’t be keywords
- variables are typed
- eg
int count = 0; count++
–count
can only storeint
egers - compiler will give you errors if you try accessing a variable with the wrong type
- eg
- comments are messages/reminders for you the programmer
- for a single line, everything after
//
will be treated as a comment - for a single or multiple lines, everything between
/*
and*/
will be ignored
- for a single line, everything after
- functions (methods/subroutines- slightly different but we’ll lump them together) are like sub-programs that you can jump to. Both stops needing to duplicate code, and keeps things organized and easier to read.
Don’t worry! We’ll be using pre-made examples!
References