Presentation is loading. Please wait.

Presentation is loading. Please wait.

Repeating Instructions And Advance collection

Similar presentations


Presentation on theme: "Repeating Instructions And Advance collection"— Presentation transcript:

1 Repeating Instructions And Advance collection
AKEEL AHMED

2 Overview Loops Nested Loops Recursive Calls Two Dimensional Arrays
Array List Class

3 Loops The ability to repeat a block of code X times.
In C#, they come in 4 different variants, and we will have a look at each one of them. The while loop The do while loop The for loop The foreach loop

4 The while loop The while loop simply executes a block of code as long as the condition you give it is true. A small example, and then some more explanation:

5 The do while loop The do loop evaluates the condition after the loop has executed, which makes sure that the code block is always executed at least once.

6 The for loop The for loop is a bit different. It's preferred when you know how many iterations you want, either because you know the exact amount of iterations, or because you have a variable containing the amount.

7 The foreach loop It operates on collections of items, for instance arrays or other built-in list types.

8 Nested Loops Any statement can be included within the body of a loop, which means anotherloop can be nested inside an outer loop. When this occurs, the inner nested loop is totally completed before the outside loop is tested a second time

9 Recursive Calls Another option for repeating a program statement is recursion. Recursion is a technique used where a method calls itself repeatedly until it arrives at the solution. Recursion is somewhat similar to a circular definition, in that the recursive method contains a call to itself.

10 Two-Dimensional Arrays
Two-dimensional arrays, the most common multidimensional arrays, are used to store information that we normally represent in table form. Two kinds of two-dimensional arrays can be created using C#. Rectangular Array jagged or ragged

11 Rectangular A rectangular two-dimensional array is usually visualized as a table divided into rows and columns. Much like a spreadsheet in which the rows and columns intersect, data is stored in individual cells. int [ , ] calories = new int[7, 3]; int [ , ] calories = {{900, 750, 1020}, {300, 1000, 2700}, {500, 700, 2100}, {400, 900, 1780}, {600, 1200, 1100}, {575, 1150, 1900}, {600, 1020, 1700}}; calories[0, 0].

12 Jagged Array When the number of columns in the rows must differ, a jagged, or ragged array, can be created. Jagged arrays differ from rectangular arrays in that rectangular arrays always have a rectangular shape, like a table. Jagged arrays are called ‘‘arrays of arrays.’’ One row might have five columns; another row 50 columns. To create a jagged array, you can create a one-dimensional array of type Array, and initialize each of the one-dimensional arrays separately.

13 ArrayList Class One of the limitations of the traditional array is the fact that you cannot change the size or length of an array after it is created. To give you more flexibility, .NET includes another class, the ArrayList class, which facilitates creating a list like structure that can dynamically increase or decrease in length. Like traditional arrays, indexes of ArrayList objects are zero based

14 ArrayList Example


Download ppt "Repeating Instructions And Advance collection"

Similar presentations


Ads by Google