Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why do FOR/NEXT variables end up +1 more?
#7
If it is important that no last value is assigned, one can cancel it with "If ... Exit ... End If".

Code: (Select All)

'For - Next, letzten zugewiesenen Wert verhindern - 24. Aug. 2023

$Console:Only
Option _Explicit

Dim As Integer i, j

For i = 1 To 5
  Print i
Next

Print

'Wert ist jetzt 6, da die letzte Pruefung
'der Abbruchbedingung noch an i uebergeben wird.
Print i * 5

Print: Print
Print "Letzte Zuweisung verhindern"

Print
For j = 1 To 5 Step 1
  Print j
  If j = 5 Then
    'Keine Zuweisung mehr
    Exit For
  End If
Next

Print
Print j * 5

End
Reply


Messages In This Thread
RE: Why do FOR/NEXT variables end up +1 more? - by Kernelpanic - 08-24-2023, 03:08 PM



Users browsing this thread: 4 Guest(s)