webForumDet fria alternativet

Vad är det för fel på While... Wend?

ASP

7 svar · 365 visningar · startad av trexter.com

Medlem sedan apr. 20021 203 inlägg
Frågan#1

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?!

Medlem sedan apr. 20021 203 inlägg
#2

[Detta står under [VB-script]]

Medlem sedan maj 200010 687 inlägg
#3

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.

Medlem sedan okt. 20005 273 inlägg
#4

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.

Medlem sedan dec. 200012 464 inlägg
#5

While...Wend ska vara bättre om man ser till prestanda.

Varför?

Medlem sedan maj 200010 687 inlägg
#6

Ingen aning. Bara vad jag hört. :)

Medlem sedan juni 20003 076 inlägg
#7

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)
Loop

Dim 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. :)

Medlem sedan mars 2002777 inlägg
#8

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:

  1. getstring()
  2. getrows(), loopa ut array med for-slinga
  3. do loop och while loop
268 ms totalt · 4 externa anrop · v20260731065814-full.a51de22e
124 ms — deklarationer (db)
0 ms — hämta statistik (cache)
140 ms — hämta tråd, inlägg och bilagor (db)
125 ms — ändringar (db)