This program explains how to use FOR loop in VB programming.
FOR Loop allows us to run one or more lines of code repeatedly without any break. FOR loop will break if the condition that you are given become false, otherwise it will continue.
Mainly used loops in VB.NET:
DO WHILE Loop
In FOR Loop, your desired code must be inside FOR Statement.
Syntax for FOR Loop
For (counter = startvalue;(counter<=EndValue);Counter++)
//Code to be executed for each value of counter.
- Counter – Numeric value or counter for repeating the loop.
- StartValue – Value from where the counter starts the loop.
- EndValue – Valuefrom where the counter stops the loop
Using FOR loop in C# – Complete Code for FOR LOOP
public partial class Form1 : Form
private void button1_Click(object sender, EventArgs e)
StartValue = 1;
EndValue = 10;
for (Counter = StartValue; (Counter <= EndValue); Counter++)
MessageBox .Show (("Counting Starts from "
+ (Counter + (" Counting ends in " + EndValue))));
Using FOR loop in C# – Working with steps
- Step 1: You have to declare Counter, StartValue, EndValue as integer
- Step 2: Set StartValue as 1 (here you set the value where counter starts)
- Step 3: Set EndValue as 10 (Here you set the value where the loop stops)
- Step 4: Assign the StartValue to the counter and starts loop until the counter reaches the EndValue.
- Step 5: Executing the loop body, till the counter reaches end and finally loops out.
If you have any suggestions or doubts regarding FOR Loop in C#, please contact us our Mail ID: Codingangel@gmail.com
Using FOR Loop in C#