Hello,
Could any one tell me why and when
we use do loops with example .
Bye
Printable View
Hello,
Could any one tell me why and when
we use do loops with example .
Bye
Do loops are used to repeat some event until some action happens which is going to stop the loop.This loop will loop until or while that action has happened.It is mosy often used when we don't know how many times we want something to happen but it depends of the user or smth. else.
This will move the form down while its top position is smaller than 5000.Code:Do While Form1.Top < 5000
Form1.Top = Form1.Top + 20
Loop
This does the same thing just instead of while we use until.Code:Do Until Form1.Top > 5000
Form1.Top = Form1.Top + 20
Loop
Code:Dim f as integer
f = freefile
Dim InputStr as string
open "C:\Windows\desktop\mydata.txt" for input as #f
do while not EOF(f)
line input #f,inputstr
'do some processing with each line of the file
loop
close #f
If you know how many times you want to loop, it's better to use a For loop as it is slightly faster.
Code:For I = 0 To MyNumber 'i.e 1000
Print "Hello"
Next I