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

Slides:



Advertisements
Similar presentations
JQuery MessageBoard. Lets use jQuery and AJAX in combination with a database to update and retrieve information without refreshing the page. Here we will.
Advertisements

Microsoft Visual Basic: Reloaded Chapter Seven More on the Repetition Structure.
CS0004: Introduction to Programming Repetition – Do Loops.
MIS 3200 – Unit 4 Complex Conditional Statements – else if – switch.
Control structures Part 2 iteration control To enable repetition of a statement block.
Macros Tutorial Week 20. Objectives By the end of this tutorial you should understand how to: Create macros Assign macros to events Associate macros with.
Control Structures - Repetition Chapter 5 2 Chapter Topics Why Is Repetition Needed The Repetition Structure Counter Controlled Loops Sentinel Controlled.
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.
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
CHAPTER 6 Loop Structures.
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.
Database-Driven Web Sites, Second Edition1 Chapter 8 Processing ASP.NET Web Forms and Working With Server Controls.
Unit 8.2 Learning Objectives How data can be used – The Money Ball Example The Money Ball Example Data Warehouses – The Role of Data Warehouses The Role.
Introduction to Graphical User Interfaces. Objectives * Students should understand what a procedural program is. * Students should understand what an.
Microsoft Visual Basic 2008 CHAPTER 8 Using Procedures and Exception Handling.
 What are the different types of loops? ◦ Do….While  Performs statements within loop while a condition is true ◦ Do….Until  Performs statements within.
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
06/10/ Working with Data. 206/10/2015 Learning Objectives Explain the circumstances when the following might be useful: Disabling buttons and.
07/10/ Strings ASCII& Processing Strings with the Functions - Locate (Instr), Mid, Length (Len), Char (ChrW) & ASCII (Asc)
UNIT 9.2: Learning Objectives Agile Development – Bruce Feiler on Agile Programming Database access from code – Database Cycle Review – SQL Command Types.
Introduction to Arrays. definitions and things to consider… This presentation is designed to give a simple demonstration of array and object visualizations.
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.
MIS 3200 – Unit 4.2 ListItem controls – CheckBoxList – ListBox.
Program Design and Coding
Unit 8.3 Learning Objectives Insert users into the ASP.NET Membership system from code Capture data being sent to the database Capture Exceptions that.
MIS 3200 – Unit 3 What can computers do – Follow a sequence of instructions – Follow different paths of instructions based on decisions – Do things over.
Mr. Dave Clausen1 La Cañada High School Chapter 6: Repetition Statements.
MIS 3200 – Unit 5.3 Manipulating ListItem controls – Moving ListItems between ListItem controls – Removing ListItems from ListItem controls.
Control Structures II Repetition (Loops). Why Is Repetition Needed? How can you solve the following problem: What is the sum of all the numbers from 1.
An Object-Oriented Approach to Programming Logic and Design Fourth Edition Chapter 4 Looping.
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.
Class 3 Remote Instruction Computer Math EDU 556 Programming for Instruction Dr. Steve Broskoske This is an audio PowerCast. Make sure your volume is.
CS161 Topic #16 1 Today in CS161 Lecture #16 Prepare for the Final Reviewing all Topics this term Variables If Statements Loops (do while, while, for)
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.
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
For…Next Loops, Checked List Boxes, and Combo Boxes Chapter 5.
This is how you invoke the Microsoft Visual Studio 2010 Software. All Programs >> Microsoft Visual Studio 2010.
Iterations (aka Loops). 2 Loops Loops (iterations) are segments of code that may be executed several times. Fixed-count (definite) loops repeat a fixed.
Visual Basic.NET BASICS Lesson 11 List Boxes, For Next Loops, and Label Settings.
Controlling Program Flow with Looping Structures
Unit 6 Repetition Processing Instructor: Brent Presley.
Unit 8.2 Learning Objectives Data Warehouses – The Role of Data Warehouses The Role of Data Warehouses – Group Exercise Accessing Data in Views – Accessing.
More Visual Basic!. Creating a Standalone Program A standalone program will allow you to make a program file that can be run like other Windows programs,
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.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 6 Looping and Multiple Forms.
Chapter 6 Controlling Program Flow with Looping Structures.
111 State Management Beginning ASP.NET in C# and VB Chapter 4 Pages
26/06/ Iteration Loops For … To … Next. 226/06/2016 Learning Objectives Define a program loop. State when a loop will end. State when the For.
Visual Basic Fundamental Concepts
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
Unit 8.2 How data can be used Accessing Data in Views
While Loops Chapter 3.
Chapter 6 – Repetition 6.1 Do Loops 6.2 For...Next Loops
MIS 3200 – Unit 3 What can computers do
MIS 3200 – Unit 4 Complex Conditional Statements else if switch.
When I want to execute the subroutine I just give the command Write()
Visual Basic..
MIS 3200 – Unit 5.2 ListItem controls and accumulation
Loops CIS 40 – Introduction to Programming in Python
Web Development Using ASP .NET
MIS 3200 – Unit 5.1 Iteration (looping) Working with List Items
MIS 3200 – Unit 6.1 Moving between pages by redirecting
MIS 3200 – Unit 2.2 Outline What’s the problem with bad data?
The Step Parameter & Nested For … To … Next loops
Presentation transcript:

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

Loop – Walk though 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)

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 instead of 2.5, or just have completely different values.

Time to try it out – L1 While and For loops 1.Create a new web page in Unit5 2.Name the web page lastnameU5L1.aspx 3.Create a heading in the content area called UNIT 5 L1 WORKING WITH LOOPS and make it an h2 heading 4.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) 5.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) 6.Back in 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 7.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 8.Press enter after this new button and add a one more new button Change the Text to Demonstrate a FOR loop Give it an appropriate name and set the appropriate output label’s visible property to true 9.Double-click on the both buttons to create their click event methods 10.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) 11.In your while button method, enter this code:

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

L1 #8 7.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?