Page 1 of 1

Math expressions in control commands

PostPosted: Fri Jul 08, 2016 6:53 am
by reinier maliepaard
Hello,

You probably know the use of math expressions in Neobook's SetVar:

Code: Select all
SetVar "[z]" "10"
SetVar "[z]" "[z]+1"

However, math expressions can used in e.g. the control commands If, IfEx, While, WhileEx and Loop also, resulting in shorter code. I did not find a post on this topic. So I made some examples for you and hope you'll find these helpful.

Best regards,
Reinier

Code: Select all
...................................................................
.Examples of math expressions in Neobook's SetVar and
.control commands If, IfEx, While, WhileEx and Loop
...................................................................
SetVar "[x]" "3"
SetVar "[y]" "2"
SetVar "[z]" "1"
...................................................................
...................................................................
While "[z]" "<" "3"
 AlertBox "Result 1" "Value of variable z: [z]"
 SetVar "[z]" "[z]+1"
EndWhile
......................................................................
If "[x]+[y]" ">" "[z]"
 AlertBox "Result 2" "[x]+[y] > [z] is TRUE"
Else
 AlertBox "Result 2" "[x]+[y] > [z] is FALSE"
EndIf
......................................................................
IfEx "[x]+[y] > [z] AND [x]-[y] = [z]"
 AlertBox "Result 3" "[x]+[y] > [z] AND [x]-[y] = [z] is TRUE"
Else
 AlertBox "Result 3" "[x]+[y] > [z] AND [x]-[y] = [z] is FALSE"
EndIf
......................................................................
WhileEx "[x]^2 > 0 AND [x]*[y] > 0"
  AlertBox "Result 4" "Value of variable x and y: [x] and [y]"
  SetVar "[x]" "[x]-1"
  SetVar "[y]" "[y]-1"
EndWhile
......................................................................
.initialize [y] again because of the last example
SetVar "[y]" "2"
......................................................................
If "Sqrt([y])" "<" "[z]"
 AlertBox "Result 5" "Sqrt([y]) < [z] is TRUE"
Else
 AlertBox "Result 5" "Sqrt([y]) < [z] is FALSE"
EndIf
......................................................................
.solving an equation for a > 0
Loop "1" "Sqr([y]+[z])" "[a]"
 If "[a]*[a]-3*[a]-3" "=" "[a]-3"
  AlertBox "Result 6" "a*a-3a-3 = a-3 is TRUE for value [a]"
  ExitLoop
 EndIf
EndLoop
......................................................................
......................................................................
. Try it yourself and use Neobook's math operators and functions:
. +  -  *  /  ^
. Abs
. Sin  Cos  Atan,
. Sqr  Sqrt  Round Trunc

Re: Math expressions in control commands

PostPosted: Fri Jul 08, 2016 5:46 pm
by Neosoft Support
I think you're right that not everyone is aware of this. Thank you for posting it.

Re: Math expressions in control commands

PostPosted: Sun Jul 10, 2016 10:00 am
by Wrangler
Thanks, Reinier!