Posted: 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)=1and dice(2)=1and dice(3)=1and dice(4)=1and dice(5)=1or%much more code end ones
Please specify what version of Turing you are using
Turing 4.1.1 or whatever is latest
Sponsor Sponsor
Insectoid
Posted: Wed Jan 18, 2012 5:20 pm Post subject: RE:And/or in turing
&& = and
|| = or
Raknarg
Posted: 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
Posted: 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 endif endfor if(allTrue)then %stuff to do endif