[Detta står under [VB-script]]
På w3schools.com står det så här (utan någon förklaring):
"While...Wend statement - Do not use it - use the Do...Loop statement instead "
Varför? Vad är det för fel på att använda detta?!
7 svar · 365 visningar · startad av trexter.com
På w3schools.com står det så här (utan någon förklaring):
"While...Wend statement - Do not use it - use the Do...Loop statement instead "
Varför? Vad är det för fel på att använda detta?!
[Detta står under [VB-script]]
Låter lite märkligt. While...Wend ska vara bättre om man ser till prestanda.
Däremot kan man t.ex. inte använda Exit Do som man kan med Do...Loop.
klippt ur Microsoft.com
Visual Basic Scripting Edition
While...Wend Statement
Executes a series of statements as long as a given condition is True.While condition
Version [statements]
Wend
Arguments
condition
Numeric or string expression that evaluates to True or False. If condition is Null, condition is treated as False.
statements
One or more statements executed while condition is True.
Remarks
If condition is True, all statements in statements are executed until the Wend statement is encountered. Control then returns to the While statement and condition is again checked. If condition is still True, the process is repeated. If it is not True, execution resumes with the statement following the Wend statement.While...Wend loops can be nested to any level. Each Wend matches the most recent While.
Note The Do...Loop statement provides a more structured and flexible way to perform looping.
The following example illustrates use of the While...Wend statement:Dim Counter
Counter = 0 ' Initialize variable.
While Counter < 20 ' Test value of Counter.
Counter = Counter + 1 ' Increment Counter.
Alert Counter
Wend ' End While loop when Counter > 19.
Ingen aning. Bara vad jag hört. :)
Fortsättning från microsoft:
Arguments
condition
Numeric or string expression that is True or False. If condition is Null, condition is treated as False.
statements
One or more statements that are repeated while or until condition is True.
Remarks
The Exit Do can only be used within a Do...Loop control structure to provide an alternate way to exit a Do...Loop. Any number of Exit Do statements may be placed anywhere in the Do...Loop. Often used with the evaluation of some condition (for example, If...Then), Exit Do transfers control to the statement immediately following the Loop.When used within nested Do...Loop statements, Exit Do transfers control to the loop that is nested one level above the loop where it occurs.
The following examples illustrate use of the Do...Loop statement:
Do Until DefResp = vbNo
MyNum = Int (6 * Rnd + 1) ' Generate a random integer between 1 and 6.
DefResp = MsgBox (MyNum & " Do you want another number?", vbYesNo)
LoopDim Check, Counter
Check = True: Counter = 0 ' Initialize variables.
Do ' Outer loop.
Do While Counter < 20 ' Inner loop.
Counter = Counter + 1 ' Increment Counter.
If Counter = 10 Then ' If condition is True...
Check = False ' set value of flag to False.
Exit Do ' Exit inner loop.
End If
Loop
Loop Until Check = False ' Exit outer loop immediately.
den stora skillnaden är väl att man kan avbryta en do-loop men inte en while-loop och i och med det är do-loopen mer flexibel. :)
Om man tittar på loopning av recsets så borde både en do loop och en while loop vara hugget som stucket. Den tar en post, skriver ut, går in och hämtar nästa, skriver ut osv ev hämtar den gruppvis. Medan om du loopar ut en array som du hämtat med getrows(), då har du många färre anrop till databasen och getstring() ytterligare färre. Så jag skulle vilja rangordna så här: