Revision history for KeyPgSelectcase


Revision [22286]

Last edited on 2018-04-21 06:17:02 by fxm [Added precision on value restrictions when 'As Const' is used]
Additions:
With ##**As Const**##, a jump table is created to contain the full range of integer ##**Case**##s handled. This allows ##**Select Case As Const**## to be faster than ##**Select Case**##.
However, the size of the range of values is limited, and after converting the values to the uinteger type, the largest value in the range may be no higher than the smallest value + 8191 (current implementation).
Deletions:
With ##**As Const**##, a jump table is created to contain the full range of integer ##**Case**##s handled. This allows ##**Select Case As Const**## to be faster than ##**Select Case**##. However, the size of the range of values is limited, and after converting the values to the uinteger type, the largest value in the range may be no higher than the smallest value + 8191.


Revision [22285]

Edited on 2018-04-21 02:47:14 by fxm [Added precision on value restrictions when 'As Const' is used]
Additions:
With ##**As Const**##, a jump table is created to contain the full range of integer ##**Case**##s handled. This allows ##**Select Case As Const**## to be faster than ##**Select Case**##. However, the size of the range of values is limited, and after converting the values to the uinteger type, the largest value in the range may be no higher than the smallest value + 8191.
Deletions:
With ##**As Const**##, a jump table is created to contain the full range of integer ##**Case**##s handled. This allows ##**Select Case As Const**## to be faster than ##**Select Case**##. However, the size of the range of values is limited, and the largest value in the range may be no higher than the smallest value + 8191.


Revision [22284]

Edited on 2018-04-20 16:48:21 by fxm [Last change canceled]
Additions:
With ##**As Const**##, a jump table is created to contain the full range of integer ##**Case**##s handled. This allows ##**Select Case As Const**## to be faster than ##**Select Case**##. However, the size of the range of values is limited, and the largest value in the range may be no higher than the smallest value + 8191.
Deletions:
With ##**As Const**##, a jump table is created to contain the full range of integer ##**Case**##s handled. This allows ##**Select Case As Const**## to be faster than ##**Select Case**##. However, the size of the range of values is limited, and the largest value in the range may be no higher than the smallest value + 8191 (and also all the values of the same sign).


Revision [22283]

Edited on 2018-04-20 11:40:57 by fxm [Added a restriction on values (all of the same sign) if 'As Const' is used]
Additions:
With ##**As Const**##, a jump table is created to contain the full range of integer ##**Case**##s handled. This allows ##**Select Case As Const**## to be faster than ##**Select Case**##. However, the size of the range of values is limited, and the largest value in the range may be no higher than the smallest value + 8191 (and also all the values of the same sign).
Deletions:
With ##**As Const**##, a jump table is created to contain the full range of integer ##**Case**##s handled. This allows ##**Select Case As Const**## to be faster than ##**Select Case**##. However, the size of the range of values is limited, and the largest value in the range may be no higher than the smallest value + 8191.


Revision [21134]

Edited on 2016-03-13 10:47:47 by fxm [Formatting]

No Differences

Revision [20728]

Edited on 2016-03-01 04:15:42 by fxm [variables defined inside the block are local]
Additions:

- In the //[[CompilerOptlang|-lang qb]]// and //[[CompilerOptlang|-lang fblite]]// dialects, variables declared inside a ##**Select**##..##**End Select**## block have a function-wide [[ProPgVariableScope|scope]] as in QB.
- In the //[[CompilerOptlang|-lang fb]]// and //[[CompilerOptlang|-lang deprecated]]// dialects, variables declared inside a ##**Select**##..##**End Select**## block are visible only inside the block, and can't be accessed outside it.


Revision [20516]

Edited on 2016-02-10 16:08:33 by DkLwikki [Update link format]
Additions:
- ##[[KeyPgIfthen|If...Then]]##
Deletions:
- ##[[KeyPgIfthen If...Then]]##


Revision [17828]

Edited on 2015-10-03 14:20:46 by FxMwikki [With As Const, the jump table is increased to 8192]
Additions:
With ##**As Const**##, a jump table is created to contain the full range of integer ##**Case**##s handled. This allows ##**Select Case As Const**## to be faster than ##**Select Case**##. However, the size of the range of values is limited, and the largest value in the range may be no higher than the smallest value + 8191.
Deletions:
With ##**As Const**##, a jump table is created to contain the full range of integer ##**Case**##s handled. This allows ##**Select Case As Const**## to be faster than ##**Select Case**##. However, the size of the range of values is limited, and the largest value in the range may be no higher than the smallest value + 8192.


Revision [17827]

Edited on 2015-10-03 14:02:41 by FxMwikki [With As Const, the jump table is increased to 8192]
Additions:
With ##**As Const**##, a jump table is created to contain the full range of integer ##**Case**##s handled. This allows ##**Select Case As Const**## to be faster than ##**Select Case**##. However, the size of the range of values is limited, and the largest value in the range may be no higher than the smallest value + 8192.
Deletions:
With ##**As Const**##, a jump table is created to contain the full range of integer ##**Case**##s handled. This allows ##**Select Case As Const**## to be faster than ##**Select Case**##. However, the size of the range of values is limited, and the largest value in the range may be no higher than the smallest value + 4096.


Revision [15891]

Edited on 2012-01-31 16:08:44 by FxMwikki [Remove ambiguity between 'Integer' (data-type) and 'integer' (numeric type excluding floating-point)]
Additions:
If ##**As Const**## is used, only integer constants (all numeric constants excluding the two floating-point constants: single and double) can be evaluated and the expression list supports simple constants and enumerations only. "##**To**##" ranges are supported, but "##**Is**##" relational operators are not.
Deletions:
If ##**As Const**## is used, only ##[[KeyPgInteger Integer]]## constants can be evaluated and the expression list supports single constants and enumerations only. "##**To**##" ranges are supported, but "##**Is**##" relational operators are not.


Revision [15307]

Edited on 2011-10-01 08:27:24 by DkLwikki [Add speed comparison example]
Additions:
{{fbdoc item="filename" value="examples/manual/control/select.bas"}}%%(freebasic)
{{fbdoc item="filename" value="examples/manual/control/select-speed.bas"}}%%(freebasic)
'' SELECT CASE vs. SELECT CASE AS CONST speed test
const N = 50000000
dim as integer dummy = 0
dim as double t = timer()
for i as integer = 1 to N
select case i
case 1, 3, 5, 7, 9
dummy += 1
case 2, 4, 6, 8, 10
dummy += 1
case 11 to 20
dummy += 1
case 21 to 30
dummy += 1
case 31
dummy += 1
case 32
dummy += 1
case 33
dummy += 1
case is >= 34
dummy += 1
case else
print "can't happen"
end select
next
print using "SELECT CASE: ##.### seconds"; timer() - t
t = timer()
for i as integer = 1 to N
select case as const i
case 1, 3, 5, 7, 9
dummy += 1
case 2, 4, 6, 8, 10
dummy += 1
case 11 to 20
dummy += 1
case 21 to 30
dummy += 1
case 31
dummy += 1
case 32
dummy += 1
case 33
dummy += 1
case else
if( i >= 34 ) then
dummy += 1
else
print "can't happen"
end if
end select
next
print using "SELECT CASE AS CONST: ##.### seconds"; timer() - t
sleep
Deletions:
{{fbdoc item="filename" value="examples/manual/control/select.bas"}}%%(freebasic)


Revision [14087]

Edited on 2009-01-14 20:14:21 by CountingPine [Further definition on some finer points]
Additions:
##**Select Case**## executes specific code depending on the value of an expression. The expression is evaluated once, and compared against each ##**Case**##, in order, until a matching expression is found. The code inside the matching Case branch is executed, and the program skips down to the end of the ##**Select Case**## block. ##**Case Else**## matches any case not already matched, so if there is a ##**Case Else**##, at least one ##**Case**## is guaranteed to be executed. If no ##**Case**##s match, the whole ##**Select Case**## block will be skipped.
- ##//expr//##: evaluates ##//expr//##, and compares for equality with the original expression. If they are equal, then a match has been found. This could be considered as a shorthand for "##**Is** = //expr//##" (see below).
- ##//expr1// **To** //expr2//##: evaluates ##//expr1//## and checks to see if it is less than or equal to the original expression. If so, it evaluates ##//expr2//##, and checks to see if it is greater than or equal to the original expression. If so, then a match has been found.
- ##**Is** //relational_operator// //expr//##: evaluates ##//expr//##, and compares the original operation against it, using the supplied ##//relational_operator//## (##=##, ##>##, ##<##, ##<>##, ##<=##, ##>=##). If the comparison is true, then a match has been found.
Multiple checks can be made in each ##**Case**##, by separating them by a comma (##,##). Once a match is found, the program finishes its checks, and goes on to execute the code statements for that ##**Case**## block. No further expressions are evaluated or checked.
{{table columns="2" cellpadding="1" cells="Case 1 ;constant;Case 5.4 To 10.1;range;Case Is > 3;bigger than-smaller than;Case 1, 3, 5, 7 to 9;match against a set of values;Case x ;value of a variable"}}
- in an "##//expr1// TO //expr2//##" case, QB would always evaluate both expressions, even if ##//expr1//## was higher than the original expression.
Deletions:
##**Select Case**## executes specific code depending on the value of an expression. The expression is compared against each ##**Case**##, in order, until a matching expression is found. The code inside the matching Case branch is executed, and the program skips down to the end of the ##**Select Case**## block. ##**Case Else**## matches any case not already matched, so if there is a ##**Case Else**##, at least one ##**Case**## is guaranteed to be executed. If no ##**Case**##s match, the whole ##**Select Case**## block will be skipped.
{{table columns="2" cellpadding="1" cells="Case 1 ;constant;Case 5.4 To 10.1;range;Case Is > 3;bigger than-smaller than;Case 1, 3, 5, 7, 9;enumeration;Case x ;value of a variable"}}


Revision [13770]

Edited on 2008-10-07 21:30:27 by CountingPine [Minor rewording; formatting changes]
Additions:
**Select Case** As Const //integer_expression//
##**Select Case**## executes specific code depending on the value of an expression. The expression is compared against each ##**Case**##, in order, until a matching expression is found. The code inside the matching Case branch is executed, and the program skips down to the end of the ##**Select Case**## block. ##**Case Else**## matches any case not already matched, so if there is a ##**Case Else**##, at least one ##**Case**## is guaranteed to be executed. If no ##**Case**##s match, the whole ##**Select Case**## block will be skipped.
##**End Select**## is used to close the ##**Select Case...End Select**## block.
Note for C users: In ""FreeBASIC"", ##**Select Case**## works like a ##switch## block where all cases have a ##break## at the end. As there is no fall-through, multiple options must be put in an expression list in a single ##**Case**##.
Besides integer types, floating point and string expressions are also supported with the first syntax.
##{ //expression// | //expression// **To** //expression// | **Is** //relational operator// //expression// }[, ...]##
If ##**As Const**## is used, only ##[[KeyPgInteger Integer]]## constants can be evaluated and the expression list supports single constants and enumerations only. "##**To**##" ranges are supported, but "##**Is**##" relational operators are not.
With ##**As Const**##, a jump table is created to contain the full range of integer ##**Case**##s handled. This allows ##**Select Case As Const**## to be faster than ##**Select Case**##. However, the size of the range of values is limited, and the largest value in the range may be no higher than the smallest value + 4096.
- ##**Select Case As Const**## did not exist in QB
Deletions:
Select Case As Const //integerexpression//
Select Case executes specific code depending on the value of an expression. The expression is compared against each Case, in order, until a matching expression is found. The code inside the matching Case branch is executed, and the program skips down to the end of the Select Case block. Case Else matches any Case not already matched, so if there is a Case Else, at least one Case is guaranteed to be executed. If no Cases match, the whole Select Case block will be skipped.
For C users: In FreeBASIC, ##**Select Case**## works as a switch where all cases have a "break;" at the end. As there is no fall-through, multiple options must be put in an expression list in a single ##**Case**##.
##**End Select**## can be used to exit the ##**Select Case...End Select**## block
Besides integer types, floating point and strings //expressions// are also supported with the first syntax.
##{ //expression// | //expression// TO //expression// | IS //relational operator// //expression// }[, ...]##
If AS CONST is used, only integer constants in the range 0..4097 can be evaluated and the expression list supports single constants and enumerations only. Being limited to integer values allows ##**Select Case As Const**## to be faster than ##**Select Case**##.
- SELECT CASE AS CONST did not exist in QB


Revision [11712]

The oldest known version of this page was created on 2007-11-10 11:07:12 by JeffMarshall [Minor rewording; formatting changes]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki



sf.net phatcode