Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Turing for begginners
Index -> Programming, Turing -> Turing Tutorials
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
1337_brad




PostPosted: Sat Jan 29, 2005 1:01 am   Post subject: Turing for begginners

Well this tutorial is hot!!! w00t w00t! It is for anybody who is just starting out and would like to learn the basic commands =)

Ok we will start with put and get statements. The put statement is to put a string to the screen, and it can be done in a few ways.

1:
code:

put "hi"


2:
code:

var thestring: string
thestring := "hi"
put thestring


Pretty easy eh? =)

Now the get statement. The simple get statement just gets user input from the keyboard, and puts it into a variable like so.

code:

var theanswer : string
put "Hey, what is your favorite color?"
get theanswer


This simple code would get the users favorite color from their input.

Now we can go on to loops =D. Loops are pretty much the foundation for any advanced program. Without them life would be a constant copy paste. First we will start with the basic loop, and exit when statement. A loop just keeps repeating a certain section of code until an exit when parameter is met.

code:

var thenum : int
loop
     thenum := thenum + 1
     put thenum
     exit when thenum = 10
end loop


This code just repeats adding 1 to the variable 'thenum' and puts it to the screen until it equals 10. You may have noticed that when I assigned the variable, I use ':=' instead of just '='. This is just how turing works, and if you don't put the collen before the equal sign when assigning a value to a variable, you will get an error.

Now for one of my favorite things of all! The for loop! A for loop is just like a loop, but it has a finite number of times it runs. You start at a given number, and end at another given number.
code:

for i: 1..10   % the loop starts at 1 and ends at 10
     put i
end for


This code does the same thing as the last loop did, but with much less coding required. When creating a for loop, you do not need to create the for variable (in this case it is i) turing declares it for you when it sees the for statement. Well this ends lesson one! :p I hope you have enjoyed my little intro to the basics of turing, and if you need further help with anything in turing whether it be really simple stuff, or really hard stuff, either just post in this topic, or post on the Help boards and I will be more than willing to help =D.
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Sat Jan 29, 2005 8:13 am   Post subject: (No subject)

Thanks for the tutorial Smile It would be better though if you explained what a string is and what an int is. Also, the first bit of code after you introduce the get command exits after the user inputs his answer. You should add a line put "Awesome! Your favorite colour is ", theanswer at the end, just so new programmers can see that it actually worked. Mind you, doing that would require a bit of explanation as to what that comma is doing there.
+30 BITS

Lastly, I wrote a tutorial soley on loops and for loops: it's rather in depth. For extra learning, check here.

-Cervantes
1337_brad




PostPosted: Sat Jan 29, 2005 4:26 pm   Post subject: Part 2: The Draw. series =D

Ok guys, if you are interested in Animation, or graphical programs in Turing, here is the tutorial for you to get started!!

There are lots of Draw. commands, I am just going to go over the basic ones and what they require. First of all there is the Draw.Line. The Draw.Line command is quite simple, and does just what it says, draws a line. The only parameters you need for this are x1, y1, x2, y2, color. If you don't yet know, Turing graphics are all based on pixels. x1,y1,x2,y2 are all positions within the run window, acording to pixels. For example, (10, 20), would be 10 pixels to the right of the bottom left corner, and 20 pixels up from the bottom. Anyway back to the Draw.Line command.
code:

Draw.Line(10,15,20,30,black)


This code draws a black diagonal line from (10,15) to (20,30). To draw a verticle line, you would just have to make the two X values equal to eachother and only change the Y values Like so:
code:

Draw.Line(10,20,10,100,black)


Too draw a horizontal line you just keep the Y values the same and change the X values like so:
code:

Draw.Line(20,10,100,10,black)


Ok, sorry guys my mom needs the computer, I will continue this post very soon, and finish the Draw.'s =D
quick flash




PostPosted: Mon Feb 21, 2005 9:28 pm   Post subject: (No subject)

Thanks that was really useful, i have Gr.10 computer info sci and the tutorial isnt that great.
ssr




PostPosted: Mon Feb 21, 2005 10:08 pm   Post subject: (No subject)

dont forget u can do Font.Draw to change ur font, check out the turtoial section, or press F10

Very Happy
*** Im just saying this, 'cause I really dont like the default font in turing,
Booo make ur program look bad....
HyperFlexed




PostPosted: Wed Feb 23, 2005 10:09 pm   Post subject: (No subject)

ssr wrote:
dont forget u can do Font.Draw to change ur font, check out the turtoial section, or press F10

Very Happy
*** Im just saying this, 'cause I really dont like the default font in turing,
Booo make ur program look bad....


yes, but doing this disallows the use of Text.Locate making some simple programs a pain to make. I know this because I tried, and when I got assignments in compsci, I decided that it was fruitless to waste time on such a small issue. It is advantageous when the text background needs to be transparent though.
seymournexus




PostPosted: Fri Mar 04, 2005 11:21 pm   Post subject: (No subject)

var thenum : int
loop
thenum := thenum + 1
put thenum
exit when thenum = 10
end loop

don't you need to assign thenum to 0 first? o.O?
Display posts from previous:   
   Index -> Programming, Turing -> Turing Tutorials
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 7 Posts ]
Jump to:   


Style:  
Search: