Computer Science Canada Loop within a loop? |
Author: | TipsyCzar [ Thu Sep 15, 2016 12:21 pm ] | ||
Post subject: | Loop within a loop? | ||
What is it you are trying to achieve? <I'm trying to add a loop within a loop> What is the problem you are having? <Anything I try brings me to Syntax Error> Describe what you have tried to solve this problem <Tried adding names to the loops, like : loop 1, end loop 1> Post any relevant code (You may choose to attach the file instead of posting the code if it is too long) <The code would look something like this (the code isn't used for anything, only wrote it as an example) :>
Please specify what version of Turing you are using <Turing 4.1> |
Author: | DemonWasp [ Thu Sep 15, 2016 2:06 pm ] | ||
Post subject: | RE:Loop within a loop? | ||
You need one end loop for every loop command, and one exit for every loop that you want to be able to exit. For example:
|
Author: | TipsyCzar [ Fri Sep 16, 2016 7:38 am ] | ||
Post subject: | Re: RE:Loop within a loop? | ||
Here's the last part of a program I'm working on (note that the loops start are earlier on in the code)
The first end loop go the error (Syntax Error at "loop". Expected "end if"). The elsif got the error ("elsif" without matching "if"). The end if got the error (Syntax Error at "if". Expected "end loop"). The rest of the code has no errors.[/i] |
Author: | DemonWasp [ Fri Sep 16, 2016 12:44 pm ] | ||||||
Post subject: | RE:Loop within a loop? | ||||||
You need to match the start of a block structure to its end (like a loop ... end loop or an if ... end if structure). You cannot mix-and-match. OK:
Also OK:
Wrong:
See how they aren't matched? That's what's wrong. In the future, please paste all the relevant parts of your code. It's harder to understand what your problem is if I can't see the whole thing. |