lecture-06 Lopikjjiu8iuuiujijijijioop.pptx

kingofdeath1380 3 views 13 slides Jun 22, 2024
Slide 1
Slide 1 of 13
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13

About This Presentation

jhuhujiiihbb salam hinhub uv hujbihiob h jib biukjb jhb oinbjh n kn bhibhjopiojbviguohn bgvhbn bojimknvguhijomk nbhhuoijom nbhbjknm nbvhbugyvcgv bjnjhgy8ypojmkn bvgyiuhyupoj;kmn bvghiyhuijpkmn nbvgyihuijkn bvghuijn bvgyihuijknb vgyihuijnj bvhcfyrtgvbj mnljkjpokijohubj hnjikoikmnj bjhujoikm n


Slide Content

By: M.Dawood Saddiqi Visual Programming Language Ghalib Private University

Looping to Execute Statements Repetitively Loop For … While Statement Do … Loop For Each loop C#

LOOP A statements or a group of statements that is executed repeatedly is called loop. Loop is an essential programming technique that permits the repetitive execution of a statement or a group of statements. The statement in a loop are executed for a specific number of times or until the given condition remains true.

For Loop The “for loop” statement is used to execute a set of statements repeatedly for a fixed number of times. It is also called counter loop. The general syntax is as:

While Loop While loop is used to execute a statement or a set of statement as long as the given condition remains true. While loop is a conditional loop statement. This loop is suitable for that case when the number of iteration (Repetition) of statement is not known in advance.

Syntax of While loop

Do While Loop The Do loop keeps executing its enclosed statements while condition is true. The break and continue Statements. When you break out of a loop, the loop exits immediately and execution continues at the first statement after the loop.

For each loop You use the For Each… loop to loop over elements in an array or a C# collection. This loop is great, because it automatically loops over all the elements in the array or collection—you don't have to worry about getting the loop indices just right to make sure you get all elements, as you do with a For loop. Here's the syntax of this loop:

Thesyntax of For Each loop: foreach element In group [ statements ]

string[] str = new string[5]; str[0]="Khan"; str[1]="Ali"; str[2]="Murad"; str[3]="Shan"; str[4]="Gul"; foreach (string s in str) MessageBox.Show (s); Example