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

Username:   Password: 
 RegisterRegister   
 How to make a functioning loop in Turing?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Mattlap




PostPosted: Wed Apr 27, 2011 8:42 pm   Post subject: How to make a functioning loop in Turing?

What is it you are trying to achieve?
So basically I want to learn how to program. I would love to get into a programming oriented career (I'm in Gr. 9 by the way), and I'm taking Computer tech. Right now we're doing a little programming unit and it's really interesting. I downloaded Turing for my home, and I've used it a couple times. I can do the basic things like 'put', 'get', 'if', things like that, but I tried to make a loop. I don't know what's wrong. (I should explain that this is part of a project in my class to write 10 questions. This is one of them and I want to get a level 4 [i.e. going above and beyond what is expected] but if i can't figure this out, I feel that my chances of that 4 are slipping)
Any help would be appreciated

-Matt

What is the problem you are having?
It goes into a continuous loop that I can't get out of.

Describe what you have tried to solve this problem
I've really been trying to work it out here (my house) and at school for about an hour and I haven't been able to fix it. I've followed all of the error messages to the letter. It runs fine until this point, then if you put in 'yes' to the question, it goes in a continuous loop of asking "Are you sure?" while saying "Alright, let's get started."

Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
put "Do you mind if I ask you some questions?"
Turing:


get ok
if ok = "no"
then put "Alright then let's get started"
elsif ok = "yes"
then loop
    put "Are you sure?"
    get ok
    if ok = "yes"
    then put "are you sure"
    elsif ok = "no"
    then put "Alright let's get started"
    end if
    end loop
end if




Please specify what version of Turing you are using
4.1.1
Sponsor
Sponsor
Sponsor
sponsor
Insectoid




PostPosted: Wed Apr 27, 2011 8:46 pm   Post subject: RE:How to make a functioning loop in Turing?

You need an exit statement. It's kind of like an 'if'.

code:

loop
    exit when quit = "yes"
end loop


If quit = "yes" the loop will exit.
Tony




PostPosted: Wed Apr 27, 2011 8:48 pm   Post subject: RE:How to make a functioning loop in Turing?

You will need to use exit to terminate a loop. Reading tutorials we have posted on the forums will also help with the understanding of various concepts.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Mattlap




PostPosted: Wed Apr 27, 2011 8:50 pm   Post subject: Re: How to make a functioning loop in Turing?

I'll try that right now. Thanks for the uber fast reply Very Happy
Zren




PostPosted: Wed Apr 27, 2011 8:56 pm   Post subject: RE:How to make a functioning loop in Turing?

Edit: God dammit you guys >.<'

Loops for Dummies

Turing:

View.Set("text") % Scrollbar

put "Always exit"
loop
    exit when true
end loop

put "Basics of a for loop"
var start := 0
var finish := 10

for i : start .. finish
    put i
end for

put "For loop as a reg loop"
var i := start
loop
    exit when i > 10
    put i
    i += 1
end loop

put "Alternative"
i := start
loop
    put i
    i += 1
    if i > finish then
        exit % from current loop
    end if
end loop


put "Exiting two loops at once"
% not will flip a boolean value
%    Eg: not true = false
i := start
var running := true
loop
    loop
        put i
        i += 1
        if i > finish then
        running := false
        end if
       
        exit when not running
    end loop
    exit when not running
end loop

Mattlap




PostPosted: Wed Apr 27, 2011 9:03 pm   Post subject: Re: How to make a functioning loop in Turing?

Alright so, to Insectoid: This is what happened:
So I just tried what Insectoid said, and it said that there was a syntax error on 'quit'. This is what I put (because I don't remeber how to show it like it's showed in Turing):

then loop
put "Are you sure?"
get ok
if ok = "yes"
then put "are you sure"
elsif ok = "no"
then put "Alright let's get started"
exit when quit = "yes"
end if
end loop

And as i said before, I just get a syntax error on the 'quit'.

I also tried to substitute 'quit' for 'ok' (my variable) but it just repeated "are you sure?" (like it said it twice and did the 'get' command)

And as for you Zren, all I could do was stare blankly at that, you have got to understand that i know next to nothing about programming (as I am in grade nine and this is literally my first exposure to programming)
Tony




PostPosted: Wed Apr 27, 2011 9:10 pm   Post subject: RE:How to make a functioning loop in Turing?

quit is a keyword, not a variable name. The syntax error should have mentioned something along those lines.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Mattlap




PostPosted: Wed Apr 27, 2011 9:17 pm   Post subject: Re: How to make a functioning loop in Turing?

Wow, I feel stupid now lol. Thanks so much, definately going to get that 4 now Very Happy
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 8 Posts ]
Jump to:   


Style:  
Search: