Author |
Message |
coltss
|
Posted: Fri May 15, 2009 1:43 pm Post subject: how do i get 2 or more for loops to work at the same time |
|
|
What is it you are trying to achieve?
<to get 2 for loops to work at the same time. i am trying t get 2 boxes moving in different directions and different co -ordinates>
What is the problem you are having?
i want them to work in sequence
Describe what you have tried to solve this problem
I tried putting the loops together but that does not work since the distance they travel is different.
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Please specify what version of Turing you are using
4.1 |
|
|
|
|
|
Sponsor Sponsor
|
|
|
BigBear
|
Posted: Fri May 15, 2009 1:56 pm Post subject: RE:how do i get 2 or more for loops to work at the same time |
|
|
Turing: | for h : 1 .. 10
for i : 1 .. 3
put i
end for
end for |
Think about the input of this before you run it |
|
|
|
|
|
coltss
|
Posted: Fri May 15, 2009 2:09 pm Post subject: RE:how do i get 2 or more for loops to work at the same time |
|
|
input? well the out put will be 1 2 3 - 10 times |
|
|
|
|
|
Kharybdis
|
Posted: Fri May 15, 2009 2:14 pm Post subject: RE:how do i get 2 or more for loops to work at the same time |
|
|
You would require a regular Loop command with the value increasing up to a certain increment in your code.
You can also use Nested For Loops.
And the output for bigbear's code would be 123 repeated 10 times... |
|
|
|
|
|
coltss
|
Posted: Fri May 15, 2009 2:19 pm Post subject: RE:how do i get 2 or more for loops to work at the same time |
|
|
mind giving me an example? |
|
|
|
|
|
BigBear
|
Posted: Fri May 15, 2009 2:56 pm Post subject: Re: RE:how do i get 2 or more for loops to work at the same time |
|
|
coltss @ Fri May 15, 2009 2:09 pm wrote: input? well the out put will be 1 2 3 - 10 times
Right it repeats the for loop so it starts and enters the first for loop 1st time
then it enter the second loop and repeats that for 3 times and repeats it 9 more times |
|
|
|
|
|
coltss
|
Posted: Fri May 15, 2009 3:00 pm Post subject: RE:how do i get 2 or more for loops to work at the same time |
|
|
^^ i get the idea of what its doing but i cant get these lines to move |
|
|
|
|
|
BigBear
|
Posted: Fri May 15, 2009 3:01 pm Post subject: RE:how do i get 2 or more for loops to work at the same time |
|
|
It will done then the other unless you use a process which is bad news bears
Turing: |
var columns, rows : int
put "Enter number of rows"
get rows
put "Enter number of columns"
get columns
for i : 1 .. rows
for j : 1 .. columns
put "*" ..
end for
put ""
end for |
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
BigBear
|
Posted: Fri May 15, 2009 3:04 pm Post subject: RE:how do i get 2 or more for loops to work at the same time |
|
|
What is the difference between
for i : 1.. 10
end for
and
loop
count+=1
exit when count = 10
end loop |
|
|
|
|
|
coltss
|
Posted: Fri May 15, 2009 3:16 pm Post subject: RE:how do i get 2 or more for loops to work at the same time |
|
|
nothing they will both go through that loop 10 times |
|
|
|
|
|
tjmoore1993
|
Posted: Fri May 15, 2009 3:19 pm Post subject: Re: RE:how do i get 2 or more for loops to work at the same time |
|
|
BigBear @ Fri May 15, 2009 3:04 pm wrote: What is the difference between
for i : 1.. 10
end for
and
loop
count+=1
exit when count = 10
end loop
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
The for statement speaks for itself. You are setting a counter on a single line for example
for x : 1 .. 3
x is the counter in this case and is predefined so you do not need to declare as for a loop you need to declare your counter
which can get pretty boring because you don't want to have like several counters through out the program.
The difference is efficiency and the time it takes to load. The For statement has an upper advantage and it performs better. Although loops can be good
at anytime |
|
|
|
|
|
BigBear
|
Posted: Fri May 15, 2009 3:19 pm Post subject: RE:how do i get 2 or more for loops to work at the same time |
|
|
So you could just have a loop that changes the values of two different objects.
with += and -= or have the position of one be the variable time -1 to be
try this and post your new code |
|
|
|
|
|
coltss
|
Posted: Fri May 15, 2009 3:28 pm Post subject: RE:how do i get 2 or more for loops to work at the same time |
|
|
i tried didnt work ugh i 'v got to run to work i'll ponder on it more when i get back. i feell stupid lol |
|
|
|
|
|
Kharybdis
|
Posted: Fri May 15, 2009 7:16 pm Post subject: RE:how do i get 2 or more for loops to work at the same time |
|
|
I would also suggest that you look at the graphics tutorial in the Turing Help Section, it gives a few interesting things... |
|
|
|
|
|
Dusk Eagle
|
Posted: Fri May 15, 2009 11:34 pm Post subject: Re: how do i get 2 or more for loops to work at the same time |
|
|
First of all thank you for using the correct format to post your question.
Now, I don't know why your for loops include a "maxx - maxx". This is always the same as zero, so changing it to zero would make your code clearer. Now, for our main problem, I'm going to use a for loop from 0 to maxx, but you use whatever you want. First, you take both your lines of code and stick them in the same for loop. Then, notice that when you say x, what you are really saying is 0 + x. Therefore, to make a line come from the other direction, we simply call the opposite: maxx - x. To make one line go half as fast as the other, we can simply use a div 2 statement. I made a couple of other modifications to your code, which make it work well. Since this is only one small snippet of code, I don't feel it's cheating for me to give you the code here, especially if you study it to learn for future use. Don't just use my code - understand it and tinker with it. So here it is:
Edit: Notice how I used drawline instead of drawbox? Unless there's some performance change I'm unaware of, that shouldn't make much of a difference. I did it to show that there are multiple ways of approaching this problem. |
|
|
|
|
|
|