Why do FOR/NEXT variables end up +1 more?
#14
(08-26-2023, 12:57 AM)SMcNeill Wrote: The easiest way to exit ON a number is just with a simple DO loop.
start = 10
finish = 20
increment = +1
DO
    'Whatever you want to repeat
    start = start + increment
    'Post increment work stuff, if desired
LOOP UNTIL start >= finish
Thanks! Is also a possibility - I had tried it with Sleep 10. But I didn't like it because the user should decide when to continue. Now I found it. This is how it works as desired:

Code: (Select All)

'Aus einer While-Schleife eine Sub-Prozedur aufrufen - 25./26. Aug. 2023

$Console:Only
Option _Explicit

Declare Sub Berechnen(eingabe As Integer)

Dim As Integer i, eingabe, modBedingung
Dim As String antwort

Print
Print "While-Schleife wird bis zur Eingabe durchlaufen, wobei"
Print "bei Mod 7 = 0 jedesmal eine Ausgabe erfolgt."

Print
Input "Eingabe  : ", eingabe
Input "Modangabe: ", modBedingung
Print: Print

'While-Schleife wird bis zur Eingabe durchlaufen, wobei
'bei Mod 7 = 0 jedesmal eine Ausgabe erfolgt
'Ergaenst um Aufruf eines externen Programms, wenn Bedingung erfuellt
i = 1
While i < eingabe
  i = i + 1
  If i Mod modBedingung = 0 Then
    Berechnen (i)
  ElseIf i Mod 23 = 0 Then
    Print
    Input "Weiter J/N: ", antwort
    If UCase$(antwort) = "J" Then
      Run "D:\Lab\QuickBasic64\Finanz+Mathe\Geometrie\Rechtwinkliges-Dreieck-Hypo.exe"
    Else
      Exit While
    End If
  End If
Wend

End 'Hauptprogramm

Sub Berechnen (eingabe As Integer)

  eingabe = eingabe * 3
  Print Using "Ergebnis = ###"; eingabe
End Sub
Reply


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



Users browsing this thread: 6 Guest(s)