← Back to Learning Home

Turing Programming – Part 2

Control Structures and Graphics

1. if / elsif / else

Conditional statements allow your program to make decisions based on different situations.

var mark : int
get mark

if mark >= 80 then
    put "A"
elsif mark >= 70 then
    put "B"
elsif mark >= 60 then
    put "C"
elsif mark >= 50 then
    put "D"
else
    put "F"
end if
💡 The program checks conditions from top to bottom and stops when one is true.

2. Counting with a for Loop

Use a for loop when you know exactly how many times something should repeat.

for i : 1 .. 10
    put i
end for

This prints numbers from 1 to 10.

3. while Loop

A while loop runs as long as a condition remains true. Perfect when you don't know how many repetitions are needed.

var password : string := ""

while password not= "turing123"
    put "Enter password:"
    get password
end while

put "Access granted!"
⚠️ Always make sure the condition can become false — or the loop will run forever!

4. Nested Logic

You can place statements inside other statements to create more advanced behavior.

for i : 1 .. 5
    if i mod 2 = 0 then
        put i, " is even"
    else
        put i, " is odd"
    end if
end for

This program checks whether numbers are even or odd.

5. Introduction to Graphics

Turing makes it easy to draw graphics on the screen. This is where programming becomes fun!

6. drawdot

Draw a single pixel at a location.

drawdot(200, 200, brightred)

The first number is the x-coordinate, the second is the y-coordinate.

7. drawline

Draw a line between two points.

drawline(100,100,300,300,blue)

This creates a diagonal line.

8. Using a Loop to Draw Shapes

Loops can generate graphics quickly.

for x : 0 .. 400
    drawdot(x,200,green)
end for

This draws a horizontal line made of dots.

🔥 This is the beginning of animation and game programming!

What You Should Learn Next