0% found this document useful (0 votes)
134 views11 pages

For Loop Do Loop: Do While End While Loop Do Until Loop

Loops allow code to be repeated. The main types of loops are for, do-while, and do-until. For loops repeat a specified number of times, with a start and end condition. Do-while loops execute the code block at least once, then repeat as long as the condition is true. Do-until loops are similar but repeat until the condition becomes true. Loops are useful for tasks like adding multiple numbers or reading text files line by line.

Uploaded by

Krisen Pareanen
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
134 views11 pages

For Loop Do Loop: Do While End While Loop Do Until Loop

Loops allow code to be repeated. The main types of loops are for, do-while, and do-until. For loops repeat a specified number of times, with a start and end condition. Do-while loops execute the code block at least once, then repeat as long as the condition is true. Do-until loops are similar but repeat until the condition becomes true. Loops are useful for tasks like adding multiple numbers or reading text files line by line.

Uploaded by

Krisen Pareanen
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Loop

For loop Do Loop


DoWhileEnd While Loop DoUntil Loop

What is a loop ?
A loop is something that goes round and round and round. If someone told you to move your finger around in a loop, you'd know what to do immediately. It is the same in Programming.

Without loop

what if you wanted to add up a thousand numbers? So a loop would make life a lot simpler. Just remember what they do: go round and round until you tell them to stop.

For Loop
Create a new Project. Add a button to your new Form. Double click your new button and type the following code for i

Do Loop
if we don't know how many times around the loop we want to go? Use for reading of text file. With a Do Loop we can use word s like While and Until.

For Loop
To sum up
A For loop needs a start position and an end position, and all on the same line A For loop also needs a way to get the next number in the loop Example:

DoWhile
1.

2.

Difference b/w while up and while down

The difference between the two is with the While ... part at the bottom, the code above it gets executed at least once. With the code on the first line after the word Do, the code might not get executed at all. After all, the number inside the variable might already be Greater Than 5. If it is, Visual Basic won't execute the code.

DoUntil
There's not much difference between the two, but a Do ... Until works like this.

DoUntil
We "Keep looping UNTIL the number in the variable called number is Less Than 5 The problem is, the number inside the variable is already Less Than 5. And if the number is Less than 5, then the code won't execute because it has already met the end condition.

DoUntil
Do
MsgBox number number = number + 1 Loop Until number >= 5 To sum up, use a Do Loop if you don't know what the end number is going to be, otherwise a For Loop might be better.

You might also like