Search This Blog

Wednesday, 13 December 2017

Post 3 Local/Global Variables and Logical Operators

Local/Global Variables

Global Variables are declared outside any function and they can be accessed (used) on any function in the program. Global variables then to very Unreliable and are used for quicker running code more than for reliable and stable code.
Local Variables however are declared inside a function and can be used only inside that function it's placed in.

float a = 1; --> The Global variable is declared outside the function "void my_test()"

void my_test() {

  float b = 77; --> This is the local variable and it is declared inside the known function
  println(a);

  println(b);


void setup() {

  float b = 2; --> This Local variable will not be able to be accessed by any other feature  and you will notice that Local variables names can be re-used as long as they're in different functions 

  println(a);
  println(b);
  my_test();
  println(b);

Post 2 Variables and Naming Conventions

Variables

Variables in programming are things that are assigned values and used in the following code after it. Variables are commonly referred back to when a certain value needs to be taken and used to work something else out further on.

Below is a part of an email checker that I created previously






In this code the two variables known as "foundAT" and "foundDot" are assigned values and as you can see, are later brought back up to work out whether the email entered is valid or invalid and depending on what changes with these two values final outcomes will be produced to state the final answer

Naming Conventions

In computer programming a naming convention is a set of rules for choosing the character sequence to be used for identifiers which denote variables , types functions and other entities in source code and documentation.



Friday, 1 December 2017

Post 1 Selection statements

Selection statements work when a required outcome is desired to produce a specific output if this outcome is not delivered to the selection statement something else will happen that the selection statement would've been told to do.

An Example...



Something else to talk about is "Case Select" statements.
Case select statements is another way for a programmer to test whats inside of a variable but is mainly used when you know that there is only a select amount of things that can be in the variable.

An Example...

                    CASE COMMAND$ OF
            WHEN "Move west","Move left", "Go to the door on the left","Go to the door to the west": THEN ROOM = 2
            WHEN "Move east","Move right","Go to the door on the right","Go to the door to the east": THEN ROOM = 3
            WHEN "Move north","Move up","Go to the door to the top of the room","Go to the door to the north": THEN ROOM = 4
            WHEN "Move south","Move down","Go to the door to the bottom end of the room","Go to the door to the south of the room": THEN ROOM = 5


Post 6 Sequence,selection and iteration

Sequence Sequencing is when the computer will run the code it receives, one line at a time from the top to the bottom of the requested prog...