Repeating Instructions And Advance collection

Slides:



Advertisements
Similar presentations
Arrays.
Advertisements

Two-Dimensional Arrays Chapter What is a two-dimensional array? A two-dimensional array has “rows” and “columns,” and can be thought of as a series.
Repeating Structures Do While Loops. Do While Loop While loops have a test condition before the loop –This means that java will test the condition before.
Repeating Actions While and For Loops
Tutorial 12 Working with Arrays, Loops, and Conditional Statements
C# Programming: From Problem Analysis to Program Design1 Advanced Collections C# Programming: From Problem Analysis to Program Design 3 rd Edition 8.
Loops Repetition Statements. Repetition statements allow us to execute a statement multiple times Often they are referred to as loops Like conditional.
© 2004 Pearson Addison-Wesley. All rights reserved5-1 Iterations/ Loops The while Statement Other Repetition Statements.
An Object-Oriented Approach to Programming Logic and Design Chapter 6 Looping.
Chapter 9 Introduction to Arrays
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 6 Repetition Statements.
ECE122 L9: While loops March 1, 2007 ECE 122 Engineering Problem Solving with Java Lecture 9 While Loops.
Nested Loops. Nesting Control Structures One if statement inside another one An if statement inside a loop A loop inside an if statement Control structures.
Java Unit 9: Arrays Declaring and Processing Arrays.
Chapter 6Java: an Introduction to Computer Science & Programming - Walter Savitch 1 l Array Basics l Arrays in Classes and Methods l Programming with Arrays.
CPS120 Introduction to Computer Science Iteration (Looping)
Arrays Module 6. Objectives Nature and purpose of an array Using arrays in Java programs Methods with array parameter Methods that return an array Array.
1 © 2002, Cisco Systems, Inc. All rights reserved. Arrays Chapter 7.
M180: Data Structures & Algorithms in Java Arrays in Java Arab Open University 1.
Bordoloi and Bock Control Structures: Iterative Control.
Definite Loops Instructor Rob Nash. What is Definite Looping? A loop: a block of code that is repeated a number of times A definite loop: a block of code.
CPS120 Introduction to Computer Science Iteration (Looping)
Chapter 4 Grouping Objects. Flexible Sized Collections  When writing a program, we often need to be able to group objects into collections  It is typical.
 Control Flow statements ◦ Selection statements ◦ Iteration statements ◦ Jump statements.
Decision Making and Branching (cont.)
COMPUTER PROGRAMMING 2 ArrayLists. Objective/Essential Standard Essential Standard 3.00Apply Advanced Properties of Arrays Essential Indicator 3.02 Apply.
Multidimensional Arrays Vectors of Vectors When One Is Not Enough.
Visual C# 2005 Using Arrays. Visual C# Objectives Declare an array and assign values to array elements Initialize an array Use subscripts to access.
Lecture 7 – Repetition (Loop) FTMK, UTeM – Sem /2014.
Programming in Java (COP 2250) Lecture 12 & 13 Chengyong Yang Fall, 2005.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 7A Arrays (Concepts)
Today… Preparation for doing Assignment 1. Invoking methods overview. Conditionals and Loops. Winter 2016CMPE212 - Prof. McLeod1.
LESSON 8: INTRODUCTION TO ARRAYS. Lesson 8: Introduction To Arrays Objectives: Write programs that handle collections of similar items. Declare array.
Loops causes program to execute the certain block of code repeatedly until some conditions are satisfied. Suppose you want to execute some code/s 10 times.
Comp1004: Loops and Arrays I Whiles, For and Arrays[]
CS 106 Introduction to Computer Science I 02 / 15 / 2008 Instructor: Michael Eckmann.
Chapter 6: Using Arrays.
Chapter 4 Repetition Statements (loops)
© 2016 Pearson Education, Ltd. All rights reserved.
Chapter 3: Decisions and Loops
Loop Structures.
Branching Constructs Review
C# Programming Arrays in C# Declaring Arrays of Different Types Initializing Array Accessing Array Elements Creating User Interfaces Using Windows Standards.
JavaScript: Control Statements.
Counted Loops.
While Loops BIS1523 – Lecture 12.
While loops The while loop executes the statement over and over as long as the boolean expression is true. The expression is evaluated first, so the statement.
Arrays, For loop While loop Do while loop
Outline Altering flow of control Boolean expressions
Multidimensional Arrays Vectors of Vectors
In this class, we will cover:
Iteration: Beyond the Basic PERFORM
CIS 16 Application Development Programming with Visual Basic
Arrays .
Data Structures – 2D Lists
Chapter 8: More on the Repetition Structure
Chapter 7 Part 2 Edited by JJ Shepherd
3.5- The while Statement The while statement has the following syntax:
MSIS 655 Advanced Business Applications Programming
Arrays.
Control Structures Part 2
Control Structures Part 1
In this class, we will cover:
Introduction to Programming
Based on slides created by Bjarne Stroustrup & Tony Gaddis
PROGRAM FLOWCHART Iteration Statements.
Based on slides created by Bjarne Stroustrup & Tony Gaddis
Arrays.
Looping and Repetition
Presentation transcript:

Repeating Instructions And Advance collection AKEEL AHMED

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

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

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:

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.

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.

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

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

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.

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

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].

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.

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

ArrayList Example