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

Username:   Password: 
 RegisterRegister   
 Turing Long Exit when
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Hugetanks




PostPosted: Tue Jun 05, 2018 11:27 pm   Post subject: Turing Long Exit when

So when we have a long exit when statement, it says not enough memory to indent file, when I try to indent my file. My question is that is there a way to shorten the exit when, so like if I move it to a second line by entering it, will it still work?

Thanks,

P.S: Here's my exit when: exit when (button = 1 and y >= 270 and y<= 300 and ((x >= 6 and x <= maxx div 5 - 3) or (x >= maxx div 5 + 3 and x <= 2 * maxx div 5 - 3) or (x >= 2 * maxx div 5 + 3 and x <= 3 * maxx div 5 - 3) or (x >= 3 * maxx div 5 + 3 and x <= 4 * maxx div 5 - 3) or (x >= 4 * maxx div 5 + 3 and x <= maxx - 3)))
Sponsor
Sponsor
Sponsor
sponsor
Insectoid




PostPosted: Wed Jun 06, 2018 7:28 am   Post subject: RE:Turing Long Exit when

You can separate it into as many newlines as you want, wherever it makes sense. You'd be better off putting that huge line into a function though, that returns true or false. Then your exit when statement can just be 'exit when function returns true'.
Hugetanks




PostPosted: Wed Jun 06, 2018 8:07 am   Post subject: Re: Turing Long Exit when

I read through how a function works, but I do not understand how it will help for making my exit when shorter.
Insectoid




PostPosted: Fri Jun 08, 2018 10:05 am   Post subject: RE:Turing Long Exit when

Looks like your exit when is checking if a button is clicked. Why not create a function called 'buttonClicked' that returns true if the button was clicked? Then your exit when will look exactly like this:

exit when buttonClicked() = true

But you can actually omit the = true part and just have

exit when buttonClicked()

Not only does this shorten your line, but it's also obvious what's going on. It does exactly what it says: it exits when the button is clicked. Your original line on the other hand is long, complicated, full of math and generally unreadable. Nobody but you knows exactly what it does or why it's doing it. Does that make sense?
Hugetanks




PostPosted: Sat Jun 09, 2018 7:16 am   Post subject: Re: Turing Long Exit when

Hello, what I meant is that I did not understand how to apply functions into the exit when. When I read through the function tutorial, I am not sure how it will work for my program. Either that, or I do not understand how to use functions properly. Also when you say it returns true, do I use boolean and if structures? Thanks
Insectoid




PostPosted: Sat Jun 09, 2018 2:14 pm   Post subject: RE:Turing Long Exit when

A function is just a chunk of code that calculates a value. You give that chunk of code a name, just like a variable, and then you can use that chunk of code anywhere just by typing its name. In this case, you want to write a function that calculates if we should exit the loop. It doesn't actually do the exiting, just decides if we should. The value it calculates is a boolean, which is true if we should exit and false otherwise.

It will look something like this:

Function buttonClicked () : boolean %function is called buttonClicked and returns boolean
% here you can write the code that checks if your button was clicked or not. You can declare variables, do math, call other functions, etc.
If (button was clicked, aka all the code from your huge exit when) then
result true
else % if the button wasn't clicked
result false
end if
end buttonClicked

Now that we have our function, we can just write the small exit when line that I described earlier:

exit when buttonClicked()

That's all it takes!
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  [ 6 Posts ]
Jump to:   


Style:  
Search: