Answered by:
Operator Precedence
Question

I would like a list of logical, relational, equality, and mathematical operators and their order of precedence in Small Basic. I can't seem to find it any where. THANKS in advance for any help!Monday, August 9, 2010 5:06 AM
Answers

No formal documentation as yet that I know of apart from the Tutorial PDF, but a little test shows:
TextWindow.WriteLine(32+6)
TextWindow.WriteLine(3+62)
TextWindow.WriteLine(3+2*6)
TextWindow.WriteLine(3*6+2)
TextWindow.WriteLine(3+2/6)
TextWindow.WriteLine(3/6+2)
TextWindow.WriteLine(3*2/6)
TextWindow.WriteLine(3/6*2)
Therefore * and / are equal precedence and are above + and 
Other opertators are inside the Math function (SquareRoot, Trig, Min etc) and are therefore not true operators
The logical And and Or can be used in If statements to make compound logical statements with equal precedence
The comparitors =, <, <=, >, >= and <> can be used to give logical results for If conditionals and can be used with the string variables "True" and "False".
Currently some of the <, > etc don't work with String variables, only +, = and <> work with strings.
X[1] = "Hello"
If (1<>2 Or Array.ContainsIndex(X,1) And Array.ContainsIndex(X,2)="False") Then
Sound.PlayChimesAndWait()
EndIf
If ("Hello" < "Goodbye" Or "Hello" > "Goodbye" Or "Hello" = "Goodbye") Then
Sound.PlayChimesAndWait() 'Fails
EndIf
If ("Hello" <> "Goodbye") Then
Sound.PlayBellRingAndWait()
EndIf
All variables are of Type Primitive , and interpreted depending on context at compile time
TextWindow.WriteLine("2"+3)
TextWindow.WriteLine("A"+3)
pi = Math.Pi
TextWindow.WriteLine("pi = "+pi)
TextWindow.WriteLine(6/"two") ' returns 0 as a failure
As usual, I wouldn't assume precedence, rather use brackets to make things clear, in any case, + and */ are the only ones to worry about I think. Marked as answer by litdev Sunday, August 22, 2010 9:10 PM
Monday, August 16, 2010 8:01 PM
All replies

go to the site smallbasic.com and click to
Tutorial (PDF) or
Referencce Documentation or
Wiki or
Recipes.
Best Regards MartinMonday, August 9, 2010 9:32 AM 
Thanks for your quick reply, however none of those links have a list of operators with the order of precedence. For example, if you click this site: http://msdn.microsoft.com/enus/library/fw84t893%28VS.80%29.aspx you'll find the operators and order of precedence for Visual Basic .NET. There are sites with the same information for C, C++, C# and most other languages. Believe it or not, the operators and precedence are NOT identical between languages.
So what I'm looking for is a list of all available Small Basic operators, logical, relational, equity and mathematical, and the appropriate order of precedence. I teach computer science and in order to use any language well, you need to know the operators available.
Thanks again, Lisa
Monday, August 9, 2010 9:44 PM 
No formal documentation as yet that I know of apart from the Tutorial PDF, but a little test shows:
TextWindow.WriteLine(32+6)
TextWindow.WriteLine(3+62)
TextWindow.WriteLine(3+2*6)
TextWindow.WriteLine(3*6+2)
TextWindow.WriteLine(3+2/6)
TextWindow.WriteLine(3/6+2)
TextWindow.WriteLine(3*2/6)
TextWindow.WriteLine(3/6*2)
Therefore * and / are equal precedence and are above + and 
Other opertators are inside the Math function (SquareRoot, Trig, Min etc) and are therefore not true operators
The logical And and Or can be used in If statements to make compound logical statements with equal precedence
The comparitors =, <, <=, >, >= and <> can be used to give logical results for If conditionals and can be used with the string variables "True" and "False".
Currently some of the <, > etc don't work with String variables, only +, = and <> work with strings.
X[1] = "Hello"
If (1<>2 Or Array.ContainsIndex(X,1) And Array.ContainsIndex(X,2)="False") Then
Sound.PlayChimesAndWait()
EndIf
If ("Hello" < "Goodbye" Or "Hello" > "Goodbye" Or "Hello" = "Goodbye") Then
Sound.PlayChimesAndWait() 'Fails
EndIf
If ("Hello" <> "Goodbye") Then
Sound.PlayBellRingAndWait()
EndIf
All variables are of Type Primitive , and interpreted depending on context at compile time
TextWindow.WriteLine("2"+3)
TextWindow.WriteLine("A"+3)
pi = Math.Pi
TextWindow.WriteLine("pi = "+pi)
TextWindow.WriteLine(6/"two") ' returns 0 as a failure
As usual, I wouldn't assume precedence, rather use brackets to make things clear, in any case, + and */ are the only ones to worry about I think. Marked as answer by litdev Sunday, August 22, 2010 9:10 PM
Monday, August 16, 2010 8:01 PM 
THANK YOU!Tuesday, August 24, 2010 4:24 AM