Posted: Wed Feb 27, 2013 1:43 pm Post subject: Help for if statements
I was just wondering if I can use if statements like this (For an example):
Turing:
var operation :int put"Type and enter 1 for operation 1, 2 for operation 2, or 3 for operation 3." get operation
if1then put"1+1=",1 + 1 elsif2then put"1+2=",1 + 2 else put"1+3=",1 + 3 endif
Would that work? I've only used booleans for my if statements so far, but I'd like to try this, but I'm not sure if it works (last time I remember doing something like that, it failed).
Sponsor Sponsor
Tony
Posted: Wed Feb 27, 2013 5:28 pm Post subject: RE:Help for if statements
you could read the documentation -- if -- to see exactly what you can do with the statement.
Posted: Wed Feb 27, 2013 7:39 pm Post subject: RE:Help for if statements
The nice thing about programming is that if you want to try something, you can.
storm2713687
Posted: Thu Feb 28, 2013 8:31 pm Post subject: Re: RE:Help for if statements
Insectoid @ Wed Feb 27, 2013 7:39 pm wrote:
The nice thing about programming is that if you want to try something, you can.
I was at school so I couldn't use Turing xD
Since there's compsci at high schools, the computer probably had it, but I just didn't know the location of it. Thanks for helping though, guys!
jbking
Posted: Fri Mar 01, 2013 12:30 pm Post subject: Re: Help for if statements
Case would be like what you want so there is a command to do that, if you want to know about it.[/url]
yazdmich
Posted: Fri Mar 01, 2013 12:55 pm Post subject: Re: Help for if statements
Turing:
var op :int put"Type and enter 1 for operation 1, 2 for operation 2, or 3 for operation 3." get op
if op =1then put"1+1=",1 + 1 elsif op =2then put"1+2=",1 + 2 else put"1+3=",1 + 3 endif
You must tell the compiler what variable to read, easy mistake, Turing's compiler is highly declarative. almost nothing is inferred (constant typing [int, real, nat, string etc] can be inferred, but everything else is declared)
storm2713687
Posted: Fri Mar 01, 2013 5:11 pm Post subject: Re: Help for if statements
Jbking, what do you mean by that?
yazdmich @ Fri Mar 01, 2013 12:55 pm wrote:
Turing:
var op :int put"Type and enter 1 for operation 1, 2 for operation 2, or 3 for operation 3." get op
if op =1then put"1+1=",1 + 1 elsif op =2then put"1+2=",1 + 2 else put"1+3=",1 + 3 endif
You must tell the compiler what variable to read, easy mistake, Turing's compiler is highly declarative. almost nothing is inferred (constant typing [int, real, nat, string etc] can be inferred, but everything else is declared)
Can you give an example plz?
I don't quite understand that
yazdmich
Posted: Fri Mar 01, 2013 5:39 pm Post subject: Re: Help for if statements
storm2713687 @ Fri Mar 01, 2013 5:11 pm wrote:
Jbking, what do you mean by that?
yazdmich @ Fri Mar 01, 2013 12:55 pm wrote:
Turing:
var op :int put"Type and enter 1 for operation 1, 2 for operation 2, or 3 for operation 3." get op
if op =1then put"1+1=",1 + 1 elsif op =2then put"1+2=",1 + 2 else put"1+3=",1 + 3 endif
You must tell the compiler what variable to read, easy mistake, Turing's compiler is highly declarative. almost nothing is inferred (constant typing [int, real, nat, string etc] can be inferred, but everything else is declared)
Can you give an example plz?
I don't quite understand that
I fixed your code so it would work in turing. declaring means to say what it is checking, in this case the value of the variable op
Sponsor Sponsor
jbking
Posted: Fri Mar 01, 2013 6:17 pm Post subject: Re: Help for if statements
I mean that the structure of code you want where you just want to state the value and have it automatically do the line you want already exists as a separate command called "case" which you may want to research. From the documentation that should look a lot like what you wanted to some degree if I interpret what you wanted correctly. Here would be an example that is similar to what you wanted:
Turing:
case mark of label9, 10:put"Excellent" label7, 8:put"Good" label6:put"Fair" label:put"Poor" endcase
storm2713687
Posted: Fri Mar 01, 2013 7:38 pm Post subject: Re: Help for if statements
yazdmich @ Fri Mar 01, 2013 5:39 pm wrote:
storm2713687 @ Fri Mar 01, 2013 5:11 pm wrote:
Jbking, what do you mean by that?
yazdmich @ Fri Mar 01, 2013 12:55 pm wrote:
Turing:
var op :int put"Type and enter 1 for operation 1, 2 for operation 2, or 3 for operation 3." get op
if op =1then put"1+1=",1 + 1 elsif op =2then put"1+2=",1 + 2 else put"1+3=",1 + 3 endif
You must tell the compiler what variable to read, easy mistake, Turing's compiler is highly declarative. almost nothing is inferred (constant typing [int, real, nat, string etc] can be inferred, but everything else is declared)
Can you give an example plz?
I don't quite understand that
I fixed your code so it would work in turing. declaring means to say what it is checking, in this case the value of the variable op
Ohhh thanks
Is it possible to change else to elsif op = 3?
jbking @ Fri Mar 01, 2013 6:17 pm wrote:
I mean that the structure of code you want where you just want to state the value and have it automatically do the line you want already exists as a separate command called "case" which you may want to research. From the documentation that should look a lot like what you wanted to some degree if I interpret what you wanted correctly. Here would be an example that is similar to what you wanted:
Turing:
case mark of label9, 10:put"Excellent" label7, 8:put"Good" label6:put"Fair" label:put"Poor" endcase
I didn't get there in turing yet xD
Thanks for helping though
Raknarg
Posted: Sat Mar 02, 2013 1:11 pm Post subject: RE:Help for if statements
Personally I wouldn't use cases in turing, they're stupid. In most languages you can set ranges, but not in Turing. With bigger ranges you might as well use ifs.
storm2713687
Posted: Sat Mar 02, 2013 7:51 pm Post subject: Re: RE:Help for if statements
Raknarg @ Sat Mar 02, 2013 1:11 pm wrote:
Personally I wouldn't use cases in turing, they're stupid. In most languages you can set ranges, but not in Turing. With bigger ranges you might as well use ifs.
Well now I know another thing not to use in turing
Btw, is it possible to have the if statement something like this:
if variable1 = yes then
put "hi"
elsif variable1 = no then
put "bye"
end if
Raknarg
Posted: Sat Mar 02, 2013 7:56 pm Post subject: RE:Help for if statements
Why not? It's essentially the same as what you were doing before.
storm2713687
Posted: Sat Mar 02, 2013 9:25 pm Post subject: Re: RE:Help for if statements
Raknarg @ Sat Mar 02, 2013 7:56 pm wrote:
Why not? It's essentially the same as what you were doing before.
Well, I just wanted to have a bigger variety of options for my if statements.
Now I have another question
Can I use an if statement within another if statement?
Tony
Posted: Sat Mar 02, 2013 9:36 pm Post subject: Re: RE:Help for if statements
storm2713687 @ Sat Mar 02, 2013 9:25 pm wrote:
Can I use an if statement within another if statement?