Basic Commands: Forward and Backward
In this section, we will explore two of the fundamental commands in Logo programming: FORWARD
and BACKWARD
. These commands are essential for moving the turtle around the screen, allowing you to create shapes and patterns as you learn more about the Logo language.
Introduction to the Turtle
In Logo, the turtle is the primary graphic object that you will manipulate. You can think of the turtle as a pen that you can move around the screen to draw various shapes. The turtle's starting position is typically the center of the screen, facing upwards.
The FORWARD Command
The FORWARD
command moves the turtle in the direction it is currently facing. The syntax for this command is as follows:
`
FORWARD `
Example:
To move the turtle forward by 100 units, you would write:`
FORWARD 100
`
When you run this command, the turtle will move straight ahead, drawing a line as it goes. The distance can be any positive number, allowing for flexible movement.
The BACKWARD Command
Similarly, the BACKWARD
command moves the turtle in the opposite direction to where it is currently facing. The syntax is:
`
BACKWARD `
Example:
If you want to move the turtle backward by 50 units, the command would look like this:`
BACKWARD 50
`
This command will also draw a line, but it will go in the reverse direction.
Practical Examples
To understand these commands better, let’s look at a practical example. Suppose we want to draw a square. A square consists of four equal-length sides, and we can use both FORWARD
and BACKWARD
commands to achieve this.
Drawing a Square
Here’s a simple sequence of commands to draw a square:`
FORWARD 100 ; Move forward 100 units
RIGHT 90 ; Turn right 90 degrees
FORWARD 100 ; Move forward 100 units
RIGHT 90 ; Turn right 90 degrees
FORWARD 100 ; Move forward 100 units
RIGHT 90 ; Turn right 90 degrees
FORWARD 100 ; Move forward 100 units
`
In this sequence, you move forward 100 units, turn right, and repeat this process until the square is complete. The RIGHT
command is used here to change the turtle's direction.
Summary
In summary, the FORWARD
and BACKWARD
commands are foundational to moving the turtle in the Logo programming environment. Mastering these commands will allow you to create more complex shapes and patterns as you advance in your Logo programming journey.
Remember:
- FORWARD
moves the turtle forward.
- BACKWARD
moves the turtle backward.
Next Steps
In the next section, we will learn about turning the turtle with commands like RIGHT
and LEFT
, which will further enhance your ability to navigate the drawing area and create intricate designs.