Loops in C# .Net

Loops

Syntax of for loop

For (initialization ;  condition , ++  (or) --)

{

Statements;

}

While Syntax

While (condition)

{

Statements ;

}

Do While Syntax

Do

{

Statements ;

} While (condition)

Example on for loop

Place a button on the form then Add 10 text boxes in to the form when clicked on a button

 

Screenshot_21

 

Open windows forms application project

Place a button

Code for button 1 click

{

Int X = 30;

For (int I =1; i<10; I++);

{

Text box t = new text box ();

  1. location = new point (100,x);

this. Controls .Add (t);

x = x + 30;

}

Press f5

Execute the project

 

Screenshot_22

Observations

In C # .net all the controls are predefined classes.