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

Username:   Password: 
 RegisterRegister   
 And/or in turing
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Guru




PostPosted: Wed Jan 18, 2012 5:15 pm   Post subject: And/or in turing

What is it you are trying to achieve?
I was wondering if there is an and/or command or it is possible to shorten the code in an if statement instead of and and and and and or and and and and ... etc


What is the problem you are having?
I am creating a Yahtzee dice game and for the scoring categories there will be many more lines of code if I don't say and/or


Describe what you have tried to solve this problem



Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Turing:

procedure ones
if dice(1)=1 and dice(2)=1 and dice(3) = 1 and dice(4)=1 and dice(5)=1 or %much more code
end ones


Please specify what version of Turing you are using
Turing 4.1.1 or whatever is latest
Sponsor
Sponsor
Sponsor
sponsor
Insectoid




PostPosted: Wed Jan 18, 2012 5:20 pm   Post subject: RE:And/or in turing

&& = and
|| = or
Raknarg




PostPosted: Wed Jan 18, 2012 5:21 pm   Post subject: RE:And/or in turing

Use loops.

For instance, in that problem you could do something like:

var valid := true
for i : 1 .. 6
if dice (i) not= 1 then
valid = false
end if
end for

if valid = true then...

There are ways so that you can shorten it even further, but thats just an idea
mirhagk




PostPosted: Wed Jan 18, 2012 5:21 pm   Post subject: RE:And/or in turing

if your checking something like the above you can shorten the code by having a for loop

Turing:

var allTrue:=true
for i:1..5
if (dice(i) not=1) then
true:=false
end if
end for
if (allTrue) then
%stuff to do
end if
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  [ 4 Posts ]
Jump to:   


Style:  
Search: