zenac
Moldy Popcorn
Posts: 41
|
Post by zenac on Dec 17, 2016 18:42:16 GMT -5
Consider the following code...
x=3 y=10 select case x case 1: y=100 exit case case 2: y=300 exit case case 4: y=400 exit case case 5: y=500 exit case end select print "y=";y
See there is NO treatment for the value "3" inside the variable "x".
Executing the code above, the output should be "y=10".
But the execution of this code brings a strange output: "y=300" (the answer if "x" was 2).
The next code contains a solution for this problem:
x=3 y=10 select case x case 1: y=100 exit case case 2: y=300 exit case ' INSERT THE TWO LINES BELOW case 3: exit case case 4: y=400 exit case case 5: y=500 exit case end select print "y=";y
Now we have the right output: "y=10"
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Dec 17, 2016 21:49:26 GMT -5
I believe this is in the BEX documentation, but that works as expected for BEX. Maybe it should be noted somewhere.
The reason for this is because of how select case translates into ASM. Rather than checking for each value in between cases, it works on a range, and if the number falls below the next value, it goes to the previous value.
|
|
|
Post by tiberiyltim on Dec 19, 2016 5:28:52 GMT -5
Case from 0 up to X.
|
|
|
Post by landeel on Dec 19, 2016 7:15:49 GMT -5
Case works this way in BEX so it can be really fast. It took me some time to figure it out also. But the select case examples included in the compiler explain it well.
|
|