5b – For Loops Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.

Slides:



Advertisements
Similar presentations
٠ Orientation ٠ Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.
Advertisements

7 – Arrays Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.
CS150 Introduction to Computer Science 1
Designing Algorithms Csci 107 Lecture 3. Designing algorithms Last time –Pseudocode –Algorithm: computing the sum 1+2+…+n –Gauss formula for 1+2+…+n Today.
CSE 113 Week 5 February , Announcements  Module 2 due 2/15  Exam 3 is on 2/15  Module 3 due 2/22  Exam 4 is on 2/25  Module 4 due 2/29.
Iteration Conditional Loops Counted Loops. Charting the Flow of Control We’ve used flow charts to visualise the flow of control. The simplest form is.
1a – Getting Started Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.
1b – Inside Visual Studio Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.
COM S 207 While-Loop Statement Instructor: Ying Cai Department of Computer Science Iowa State University
Repetition Statements Repeating an Action A specified number of times While a Condition is True Until a Condition is True.
12b. Regression Analysis, Part 2 CSCI N207 Data Analysis Using Spreadsheet Lingma Acheson Department of Computer and Information Science,
110-K1 Iterations (1) Up to now, need to call the procedure again (e.g. click again on a command button) To repeat a piece of code: Can also use loops:
12a. Regression Analysis, Part 1 CSCI N207 Data Analysis Using Spreadsheet Lingma Acheson Department of Computer and Information Science,
CIS 115 Lecture 8. There are 3 control structures common to most computer languages that determine the flow, or path of execution, of the code:  Sequential.
4c – Logical Operations Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.
3 - Variables Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.
Repetition Chapter 7. Overview u For Loop u Do Loop  Do While Loop  Do Until Loop  Do Loop While  Do Loop Until u Nested Loops.
1 INF110 Visual Basic Programming AUBG Spring semester 2011 Reference books: Schneider D., An Introduction to Programming Using Visual Basic, Prentice.
Visual Basic.net Loops. Used to do multiple executions of the same block of code Do while loops Do until loops For next loops.
9c. Line Charts CSCI N207 Data Analysis Using Spreadsheet Department of Computer and Information Science, IUPUI Lingma Acheson
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 7 Clicker Questions September 22, 2009.
1 CSCI N201 Programming Concepts and Database 9 – Loops Lingma Acheson Department of Computer and Information Science, IUPUI.
6c – Function Procedures Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.
1 Chapter 9. To familiarize you with  Simple PERFORM  How PERFORM statements are used for iteration  Options available with PERFORM 2.
ITERATIVE STATEMENTS. Definition Iterative statements (loops) allow a set of instruction to be executed or performed several until condition are met.
Program Design. The design process How do you go about writing a program? –It’s like many other things in life Understand the problem to be solved Develop.
1 A Balanced Introduction to Computer Science, 2/E David Reed, Creighton University ©2008 Pearson Prentice Hall ISBN Chapter 13 Conditional.
For Code Next For Code Next A loop is a segment of a code that repeats (changing slightly each time)
9e. Scatter Charts CSCI N207 Data Analysis Using Spreadsheet Department of Computer and Information Science, IUPUI Lingma Acheson
Counting Loops.
2d – CheckBox Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
2e – RadioButtons Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.
7. Data Import Export Lingma Acheson Department of Computer and Information Science IUPUI CSCI N207 Data Analysis Using Spreadsheets 1.
6b – Sub Procedure With Parameters Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.
A Balanced Introduction to Computer Science, 3/E David Reed, Creighton University ©2011 Pearson Prentice Hall ISBN Chapter 13 Conditional.
2c – Textboxes and Buttons Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.
The Accumulator Pattern Summing: Add up (“accumulate”), e.g. 1 2 plus 2 2 plus 3 2 plus … plus Variation: Form a product (instead of sum), e.g.
9d. Pie Charts CSCI N207 Data Analysis Using Spreadsheet Department of Computer and Information Science, IUPUI Lingma Acheson
5a – While Loops Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.
Learning Javascript From Mr Saem
6d – Built-in Procedures Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.
Class Orientation Lingma Acheson Department of Computer and Information Science IUPUI CSCI N207 Data Analysis with Spreadsheets 1.
UCT Department of Computer Science Computer Science 1015F Iteration
UNIT 5 Lesson 15 Looping.
- Standard C Statements
Department of Computer Science
Tutorial 10 – Class Average Application Introducing the Do…Loop While and Do…Loop Until Repetition Statements Outline Test-Driving the Class Average.
Chapter 4 LOOPS © Bobby Hoggard, Department of Computer Science, East Carolina University / These slides may not be used or duplicated without permission.
- Additional C Statements
Chapter (3) - Looping Questions.
75 Has 7 in the tens place Odd Number Less than 100
Iteration: Beyond the Basic PERFORM
CSCI N207 Data Analysis Using Spreadsheet
Programming Concepts and Database
CSCI N207 Data Analysis Using Spreadsheet
2g – ComboBox Lingma Acheson CSCI N331 VB .NET Programming
7 – Variables, Input and Output
4 – History of Programming Languages
Dale Roberts, Lecturer IUPUI
Conditional Loops Counted Loops
Python While Loops.
12 Has 1 in the tens place Even Number Less than 20
Department of Computer Science
Dale Roberts, Lecturer IUPUI
2b – Labels and Pictures Lingma Acheson CSCI N331 VB .NET Programming
Chapter 13 Conditional Repetition
Programming Concepts and Database
4a- If And Else Lingma Acheson CSCI N331 VB .NET Programming
4d – Program Design Lingma Acheson CSCI N331 VB .NET Programming
Presentation transcript:

5b – For Loops Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming

Loops – For Next 2 Another variation of Loops – use a counter to determine when to exit the loop –Need a counter variable. –Need a starting value for the counter variable. –Need an ending value for the counter variable so the loop can stop. –Need to specify how the counter is changed so it can reach the stopping condition. Counter is changed after the loop body is executed.

Loops – For Next 3 E.g. Output ten lines of **************: For intCounter = 1 To 10 Step 1 lstOutput.Items.Add(“**********”) Next Can achieve the same effect by using a Do While Loop: intCounter = 1 Do While intCounter <= 10 lstOutput.Items.Add(“**********”) intCounter = intCounter + 1 Loop

Loops – For Next 4 E.g. Add up all the integers from 1 to 100 ‘Notice that the counter variable is used in the computation For intCounter = 1 To 100 Step 1 intSum = intSum + intCounter Next Step 1 can be omitted if increment by 1. The above is the same as: For intCounter = 1 To 100 intSum = intSum + intCounter Next

Loops – For Next 5 Other examples: ‘Add up 0, 2, 4, 6, 8, … For intCounter = 0 To 15 Step 2 ‘ increase counter by 2 intSum = intSum + intCounter Next ‘Add up 0, 3, 6, 9, … For intCounter = 0 To 15 Step 3 ‘ increase counter by 3 intSum = intSum + intCounter Next ‘Output all the odd numbers smaller than 20 For intCounter = 1 To 20 Step 2 ‘ increase counter by 2 lstOutput.Items.Add(intCounter) Next