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

Username:   Password: 
 RegisterRegister   
 Increasing Loop
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
gothic-sorceress




PostPosted: Tue Sep 30, 2008 11:57 am   Post subject: Increasing Loop

I need to make a loop that increases by a number that is increasing, if that makes any sense?
Sponsor
Sponsor
Sponsor
sponsor
Insectoid




PostPosted: Tue Sep 30, 2008 1:02 pm   Post subject: RE:Increasing Loop

Make a loop that adds 1 to a number, then add that number to another number.

code:

x += 1
y += x
Clayton




PostPosted: Tue Sep 30, 2008 1:28 pm   Post subject: RE:Increasing Loop

I think what you are looking for is a for loop. Check out the [Turing Walkthrough] (still auto-linked?) for awesome tutorials to get you started Smile
Zeroth




PostPosted: Tue Sep 30, 2008 11:56 pm   Post subject: Re: Increasing Loop

I think you are looking for a while loop actually. I use these in python:

Python:

i=o
while i!=guard_condition:
    if blah:
        i+=2
    elif blah[i]:
        i-=2


The idea is that you can modify i or the guard_condition inside the loop to continue for as long as you need to.
SNIPERDUDE




PostPosted: Wed Oct 01, 2008 6:58 am   Post subject: RE:Increasing Loop

No, in Turing you would use a for loop.

Turing:
for i : 1 .. number
    %put whatever code in here
end for
andrew.




PostPosted: Wed Oct 01, 2008 1:05 pm   Post subject: RE:Increasing Loop

There are no while loops in Turing. The closest thing really is a for loop.

Like SNIPERDUDE said, use:
Turing:
for i : 1 .. number
    %put whatever code in here
end for


By using this code, you are starting at 1 and counting up to whatever "number" happens to be.
[Gandalf]




PostPosted: Wed Oct 01, 2008 1:21 pm   Post subject: Re: RE:Increasing Loop

andrew. @ 2008-10-01, 1:05 pm wrote:
There are no while loops in Turing. The closest thing really is a for loop.

Uhm. There's loop, which is a heck of a lot closer to a while loop than a for loop, seeing as the for loop is... a for loop.

Turing's "while loop":
Turing:
loop
    exit when <condition>
end loop
Tony




PostPosted: Wed Oct 01, 2008 1:21 pm   Post subject: RE:Increasing Loop

a while loop in Turing is
Turing:

loop
   exit when condition
   ...
end loop


a do while loop simply moves the exit condition to the bottom of the loop

Turing:

loop
   ...
   exit when condition
end loop
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Sponsor
Sponsor
Sponsor
sponsor
Insectoid




PostPosted: Wed Oct 01, 2008 7:06 pm   Post subject: RE:Increasing Loop

The point is, the easiest way (IMO) is to use a for loop.
OneOffDriveByPoster




PostPosted: Wed Oct 01, 2008 8:43 pm   Post subject: Re: Increasing Loop

gothic-sorceress @ Tue Sep 30, 2008 11:57 am wrote:
I need to make a loop that increases by a number that is increasing, if that makes any sense?
Sounds like nested for-loops. But you really should explain more.
gothic-sorceress




PostPosted: Thu Oct 02, 2008 10:34 am   Post subject: Re: Increasing Loop

To explain further, I need to make a loop that first outputs 1, then 3, then 6, then 10, then 15, then 21, so the amount the loop increases by is increased by one for each repeat. Does that help at all?
Insectoid




PostPosted: Thu Oct 02, 2008 11:45 am   Post subject: RE:Increasing Loop

Seeing as this is going nowhere, I'll just post a simple example of one of the many ways you can do this.

code:

Answer removed.
Warchamp7




PostPosted: Thu Oct 02, 2008 12:04 pm   Post subject: Re: Increasing Loop

gothic-sorceress @ Thu Oct 02, 2008 10:34 am wrote:
To explain further, I need to make a loop that first outputs 1, then 3, then 6, then 10, then 15, then 21, so the amount the loop increases by is increased by one for each repeat. Does that help at all?


I believe this is what you are looking for

Turing:
var answerRemoved : string
Insectoid




PostPosted: Thu Oct 02, 2008 1:10 pm   Post subject: RE:Increasing Loop

Oh, come on, I had the same answer! You didn't even raise your hand! Warchamp, pshaw, more like warchump! Razz

Whatever, as long as he gets it.
Clayton




PostPosted: Thu Oct 02, 2008 1:30 pm   Post subject: RE:Increasing Loop

Just giving him the code to do it is not helping him whatsoever. Giving him hints on how to solve the problem is a much better idea.

Mull the following code over, run it, then think it over again:

Turing:
for i : 1 .. 10
    put i
end for
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  [ 15 Posts ]
Jump to:   


Style:  
Search: