How to learn to program in a simple and funny way. Learn2program

Variables

In a programming language the variables to store information are basic. DEMETER II has the following syntax for the use of variables:

  • VAR = VALUE
  • VAR++
  • VAR – –

Where VAR can be any value that the programmer uses. It can be STEPS, MINES, or whatever name the programmer chooses.

Alternatively we have the PRINT instruction to show the value of a variable on the rover’s remote control. This statement has the following syntax:

  • PRINT VAR

Below is an example of how these instructions work:

  • STEPS = 0
  • STEPS ++
  • STEPS ++
  • PRINT STEPS

With these types of instructions we can solve problems like the exercise 15:

learn to program. variables

The solution to this exercise is the following:


PASOS=0
FOR 10
   A   
   PASOS++
END
DEACT
A
PASOS++
TL
FOR 12
   A
   PASOS++
END
TR
A
PASOS++
PRINT PASOS
The Demeter Project