Computer Science, asked by angaitkar9, 9 months ago

Write a loop statements im visual basic.​

Answers

Answered by Ankush8038
2

loop statements are those in which the same functions is performed many a times..

Answered by jahnvi30
0

Answer:

Visual Basic loop structures allow you to run one or more lines of code repetitively. You can repeat the statements in a loop structure until a condition is True , until a condition is False , a specified number of times, or once for each element in a collection.

Explanation:

Do while  

counter <=1000  

num.Text=counter

counter =counter+1

Loop  

* The above example will keep on adding until counter > 1000

The above example can be rewritten as

Do  

counter=counter+1  

Loop until counter>1000

9.2 Exiting the Loop

Sometime we need exit to exit a loop earlier when a certain condition is fulfilled. The keyword to use is  Exit Do. You can examine Example 9.2 for its usage.

Example 9.2

Dim sum, n as Integer

Private Sub Form_Activate()

List1.AddItem "n" & vbTab & "sum"

Do

n=n+1

sum=sum+n-resize

List1.AddItem n & vbTab & sum

If n=100 Then

Exit Do

End If

Loop

End Sub

Explanation

In the above example, we compute the summation of 1+2+3+4+……+100.  In the design stage, you need to insert a ListBox into the form for displaying the output, named List1. The program uses the AddItem method to populate the ListBox. The statement List1.AddItem "n" & vbTab & "sum" will display the headings in the ListBox, where it uses the vbTab function to create a space between the headings n and sum.

Similar questions