
-----------------------------------
Guru
Wed Jan 18, 2012 5:15 pm

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)

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

-----------------------------------
Insectoid
Wed Jan 18, 2012 5:20 pm

RE:And/or in turing
-----------------------------------
&& = and
|| = or

-----------------------------------
Raknarg
Wed Jan 18, 2012 5:21 pm

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
Wed Jan 18, 2012 5:21 pm

RE:And/or in turing
-----------------------------------
if your checking something like the above you can shorten the code by having a for loop


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

