Control Structures and Graphics
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
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.
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!"
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.
Turing makes it easy to draw graphics on the screen. This is where programming becomes fun!
Draw a single pixel at a location.
drawdot(200, 200, brightred)
The first number is the x-coordinate, the second is the y-coordinate.
Draw a line between two points.
drawline(100,100,300,300,blue)
This creates a diagonal line.
Loops can generate graphics quickly.
for x : 0 .. 400
drawdot(x,200,green)
end for
This draws a horizontal line made of dots.