MIS 3200 – Unit 5.1 Iteration (looping) Working with List Items

Slides:



Advertisements
Similar presentations
Microsoft Visual Basic: Reloaded Chapter Seven More on the Repetition Structure.
Advertisements

CS0004: Introduction to Programming Repetition – Do Loops.
MIS 3200 – Unit 4 Complex Conditional Statements – else if – switch.
Adding Controls to User Forms. Adding Controls A user form isn’t much use without some controls We’re going to add controls and write code for them Note.
Visual Basic Fundamental Concepts. Integrated Development Enviroment Generates startup form for new project on which to place controls. Features toolbox.
MIS 3200 – Unit 6.2 Learning Objectives How to move data between pages – Using Query Strings How to control errors on web pages – Using Try-catch.
Introduction to Graphical User Interfaces. Objectives * Students should understand what a procedural program is. * Students should understand what an.
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
06/10/ Working with Data. 206/10/2015 Learning Objectives Explain the circumstances when the following might be useful: Disabling buttons and.
08/10/ Iteration Loops For … To … Next. 208/10/2015 Learning Objectives Define a program loop. State when a loop will end. State when the For.
ASP.NET Programming with C# and SQL Server First Edition Chapter 3 Using Functions, Methods, and Control Structures.
MIS 3200 – Unit 4.2 ListItem controls – CheckBoxList – ListBox.
MIS 3200 – Unit 3 What can computers do – Follow a sequence of instructions – Follow different paths of instructions based on decisions – Do things over.
MIS 3200 – Unit 5.3 Manipulating ListItem controls – Moving ListItems between ListItem controls – Removing ListItems from ListItem controls.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Class Average Application Introducing the Do...Loop While and Do...Loop Until.
Introduction to Loops For Loops. Motivation for Using Loops So far, everything we’ve done in MATLAB, you could probably do by hand: Mathematical operations.
JavaScript, Fourth Edition
Control Structures RepetitionorIterationorLooping Part I.
1 Chapter 3 – JavaScript Outline Introduction Flowcharts Control Structures if Selection Structure if/else Selection Structure while Repetition Structure.
1 Chapter 4 – Decisions 4.1 Relational and Logical Operators (see other set of slides) 4.2 If Blocks (see other set of slides) 4.3 Select Case Blocks (see.
For…Next Loops, Checked List Boxes, and Combo Boxes Chapter 5.
MIS 3200 – Unit 5.1 Iteration (looping) – while loops – for loops Working with List Items.
Iterations (aka Loops). 2 Loops Loops (iterations) are segments of code that may be executed several times. Fixed-count (definite) loops repeat a fixed.
Unit 6 Repetition Processing Instructor: Brent Presley.
Radio Buttons. Input/Form/Radio Group Use the dialog to enter label and values for the radio buttons.
Unit 8.2 Learning Objectives Data Warehouses – The Role of Data Warehouses The Role of Data Warehouses – Group Exercise Accessing Data in Views – Accessing.
Iterations (aka Loops). 2 Loops Loops (iterations) are segments of code (loop body) that may be executed several times. Fixed-count (definite) loops repeat.
CS Class 04 Topics  Selection statement – IF  Expressions  More practice writing simple C++ programs Announcements  Read pages for next.
Chapter 6 Controlling Program Flow with Looping Structures.
111 State Management Beginning ASP.NET in C# and VB Chapter 4 Pages
Zhen Jiang Dept. of Computer Science West Chester University West Chester, PA CSC530 Data Structures - LOOP 7/9/20161.
Visual Basic Fundamental Concepts
Unit 9.1 Learning Objectives Data Access in Code
REPETITION CONTROL STRUCTURE
BIT116: Scripting Loops.
Tutorial 10 – Class Average Application Introducing the Do…Loop While and Do…Loop Until Repetition Statements Outline Test-Driving the Class Average.
Tutorial 9 - Car Payment Calculator Application Introducing the while Repetition Statement Outline 9.1 Test-Driving the Car Payment Calculator Application.
ASP.NET Web Controls.
3.01 Apply Controls Associated With Visual Studio Form
Loop Structures.
Unit 8.2 How data can be used Accessing Data in Views
An Introduction to Programming and VB.NET
Visual programming Chapter 1: Introduction
3.01 Apply Controls Associated With Visual Studio Form
Dr. Ralph D. Westfall June, 2011
While Loops Chapter 3.
Using Procedures and Exception Handling
Unit 9.2 Database access from code Database Cycle Review
Chapter 6 – Repetition 6.1 Do Loops 6.2 For...Next Loops
MIS 3200 – Unit 3 What can computers do
CHAPTER FIVE Decision Structures.
MIS 3200 – Unit 4 Complex Conditional Statements else if switch.
Control Structures - Repetition
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
Visual Basic..
Unit 9.3 Learning Objectives Review database access in code
MIS 3200 – Unit 5.2 ListItem controls and accumulation
Loops CIS 40 – Introduction to Programming in Python
Do … Loop Until (condition is true)
Introduction to Problem Solving and Control Statements
Chapter 6: Repetition Statements
3.1 Iteration Loops For … To … Next 18/01/2019.
Web Development Using ASP .NET
Using C++ Arithmetic Operators and Control Structures
MIS 3200 – Unit 6.1 Moving between pages by redirecting
MIS 3200 – Unit 2.2 Outline What’s the problem with bad data?
Group Boxes, Radio buttons and Checked List Boxes
The Step Parameter & Nested For … To … Next loops
Software Development Techniques
Presentation transcript:

MIS 3200 – Unit 5.1 Iteration (looping) Working with List Items while loops for loops Working with List Items

Loop – Walk though Start the loop (A) Check a condition (B) Walkthrough Start the loop (A) Check a condition (B) If the condition is true do block (C) and then return to (B) If the condition is false Move on to step (D) Programming involves three major structures Sequences Decisions (if, switch) Loop

While loop Sample loop to add up all the numbers between 1 and 10 Create a variable to hold the sum Create a counter While the counter is <= 10 Add the counter to the sum Add one to the counter This can be any logical condition, including compound conditions using && and || Note: You can use shortcut operators and the increment operator to shorten these statements. What would that look like?

While loop using input from TextBox This example sums all the integers between zero and the number entered in a TextBox

While loop using two inputs This example sums all the integers between two numbers entered by the user lblOutput2.Text = "The sum of numbers between " + intStart.ToString(); lblOutput2.Text += "and " + intEnd.ToString(); lblOutput2.Text += "is " + intSum.ToString();

For loop Loops with the three characteristics mentioned on the last slide are so common that C# has a special control structure called a for loop just for them. In a very generic form the loop looks like this for(initialization; condition; increment) { // body of loop }

Comparing WHILE and FOR loops Initialize counter Test condition Increment counter Test condition

Working with ListItems Assume a user made these selections from a CheckBoxList called cblMenu We can determine the total number of items in the list using the Count property of the CheckBoxList’s Items collection

Working with ListItems #2 Using that count we could loop through the items in the list and see which ones are selected When we find a selected item we can get its Text or Value

Working with ListItems #3 You can access selected items from a ListBox in exactly the same way NOTE: There is a bug in the way .NET handles values in ListItem collections (CheckBoxLists, ListBoxes, and later DropDownLists) – they don’t work correctly if two items have exactly the same value! One way to get around this is to make the second item has a slightly different value such as 2.5000001 instead of 2.5, or just have completely different values.

Time to try it out – L1 While and For loops Create a new web page in Unit5 Name the web page lastnameU5L1.aspx Create a heading in the content area called UNIT 5 L1 WORKING WITH LOOPS and make it an h2 heading Open your Unit4 lastnameU422.aspx file and copy starting with the CHECKBOXLIST heading down through the output label for the checkboxlist (basically, all of the U4L2.2 content) See the next slide for the example of what to copy.

L1 #2 (what to copy)

L1 #3 (within the U4L2.2) Back in your U4L2.2 file, double-click on the Calculate sales tax and total button and copy the comments and code from within the method (everything between the start and closing squiggly) Everything between the squiggles needs to be copied

L1 #4 (back to the U5L1) Back to your U5L1 file, double-click on the Calculate sales tax and total button and paste the copied comments and code from within the method (everything between the start and closing squiggly) Once you paste your comments and code into the method, try running your U5L1 and make sure everything works just like the U42.2 at this point

L1 #5 Press enter after the Calculate sales tax and total button and add a new button Change the Text to Demonstrate a WHILE loop Give it an appropriate name and set the appropriate output label’s visible property to true Press enter after this new button and add a one more new button Change the Text to Demonstrate a FOR loop Double-click on the both buttons to create their click event methods Add appropriate comments to the methods (this method is going to demonstrate using a while/for loop to process items in a checkboxlist)

L1 #6 (while button) In your while button method, enter this code:

L1 #7 (for button) In your FOR button method, enter this code:

L1 #8 Create a link to your U5L1 page from your MIS3200 page and copy everything to ASPNET and submit your MIS Portfolio URL to the drop box.

Think About It! How is a loop more efficient than using the other conditional testing methods we looked at? Is there any time a while loop might have a strategic advantage over a for loop?