For next repetition - control statement, Visual Basic Programming

For ..... Next Repetition Statement:

To demonstrate the working of for .. next control statement, put a command button and a label control on the form. The Handle clicks the event for the command button. Now type the coding shown below as the event handler.

Private Sub Command1_Click()

Label1.Caption = "for loop illustration"

For i = 1 To 10

Form1.Print " the value of i is"; i

Next

End Sub

The Label control cannot be navigated. Whenever you press the tab key during the execution, the order in which the controls will be visited will be highlighted for every tab press. This is termed as the tab order. The Label control will not have a tab order. Primarily the Label control is used for displaying the heading. You set the caption property of the label control. During execution the caption will be exhibited on the form where the label control is placed. The common syntax of for loop is as shown below:

For index = initial value to end value (Step value)

One or more VB statements

Next

The for loop uses an index, namely "i", in this demonstration. The index is assigned the starting value, namely 1 as given. The keyword "To" tell the collection of values the index can take. The integer following "to" is the final value that is 10 in this illustration. Therefore, i, will start with 1 and raise by 1 till it reaches to 10. For each and every value of i, the statements between for and the next would be executed.

When the button is clicked "for loop illustration" will be displayed in the position where label control was placed. The following output would also be displayed on the screen as shown in figure.

the value of i is 1

the value of i is 2

the value of i is 3

....

the value of i is 10

2320_next control statement.png

Figure: Illustration of for next control statement

Specifying the Step Value:

For i = 10 To 1 Step -1

In the former for statement Step was not explicitly stated. Whenever it is not explicitly stated it is taken as 1 by default. In the above statement, the Step is specified as -1. Therefore the value will be decremented by 1 for each iteration. The index starts with 10 and is decremented by 1 for each iteration until it reaches to 1. 

Posted Date: 10/9/2012 8:30:59 AM | Location : United States







Related Discussions:- For next repetition - control statement, Assignment Help, Ask Question on For next repetition - control statement, Get Answer, Expert's Help, For next repetition - control statement Discussions

Write discussion on For next repetition - control statement
Your posts are moderated
Related Questions
i need sample balance sheet form in vb.net

In your code A, Function has to always be used on the right side of a variable assignment or in an expression. For illustration: Temp = Celsius(fDegrees) or Msg Box "The C

Sets or returns wholly qualified path to a Help File. If Help file is indicated in HelpFile, it is called automatically when the user clicks Help button (or presses the F1 key) in

types and concept of recurson

In VBScript, the While...Wend statement is provided for those who are familiar along its usage. However, due to the lack of flexibility in While...Wend, it is suggested that you us

Scenario GetLoan is a new company that will provide a loan of money to individual members of the public.   There are two types of loan to be offered: Secured Loan wher

While a run-time error takes place, the properties of the Err object are filled with information which uniquely identifies the error & information which can be used to handle it. I

Earlier versions of VBScript had no mechanism for making user-defined constants. Constants, if utilized, were implemented as variables & distinguished from other variables by using

Databound Controls - A controls use to display the contents of table using Data Control , have to bound each Control to the specific field and the controls are Known as the Data Bo

Create a project that draw a rectangle shape which may be either (*) or (+) according to the selected radio button. The number of rows in the shape will be taken from the 1 st