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

Slides:



Advertisements
Similar presentations
Looping Structures: Do Loops
Advertisements

CS107 Introduction to Computer Science Lecture 3, 4 An Introduction to Algorithms: Loops.
CS0004: Introduction to Programming Repetition – Do Loops.
Loops (Part 1) Computer Science Erwin High School Fall 2014.
Visual Basic.NET BASICS Lesson 10 Do Loops. 2 Objectives Explain what a loop is. Use the Do While and Do Until loops. Use the InputBox function. Use the.
Executes a statement or statements for a number of times – iteration. Syntax for(initialize; test; increment) { // statements to be executed } Initial.
Iteration Statements Lather Rinse Repeat. Three Iteration Statements For Each For Next While.
Tutorial 12 Working with Arrays, Loops, and Conditional Statements
CS 106 Introduction to Computer Science I 02 / 12 / 2007 Instructor: Michael Eckmann.
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.
Intro to Java while loops pseudocode. 1 A “Loop” A simple but powerful mechanism for “making lots of things happen!” Performs a statement (or block) over.
New Mexico Computer Science For All More Looping in NetLogo Maureen Psaila-Dombrowski.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 9 Car Payment Calculator Application Introducing the Do While...Loop and Do Until...Loop.
Repetition Statements Repeating an Action A specified number of times While a Condition is True Until a Condition is True.
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:
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.
6.3 List Boxes and Loops Some Properties, Methods, and Events of List Boxes List Boxes Populated with Strings List Boxes Populated with Numbers Searching.
5-1 Chapter 5 The Repetition Process in VB.NET. 5-2 Learning Objectives Understand the importance of the repetition process in programming. Describe the.
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 & Loops. One of the BIG advantages of a computer: ­It can perform tasks over and over again, without getting bored or making mistakes (assuming.
CSCI 3327 Visual Basic Chapter 4: Control Statements in Visual Basic (Part 1B) UTPA – Fall 2011.
Review for Exam2 Key Ideas 1. Key Ideas: Boolean Operators (2 > 3) || (3 < 29.3) A.True B.False C.Impossible to determine (22 > 3) && (3 > 29.3) A.True.
Visual Basic.net Loops. Used to do multiple executions of the same block of code Do while loops Do until loops For next loops.
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.
1 A Balanced Introduction to Computer Science, 2/E David Reed, Creighton University ©2008 Pearson Prentice Hall ISBN Chapter 13 Conditional.
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.
6b – Sub Procedure With Parameters Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.
Copyright © 2012 Pearson Education, Inc. Chapter 5: Loops.
Visual Basic.NET BASICS Lesson 11 List Boxes, For Next Loops, and Label Settings.
Controlling Program Flow with Looping Structures
A Balanced Introduction to Computer Science, 3/E David Reed, Creighton University ©2011 Pearson Prentice Hall ISBN Chapter 13 Conditional.
Intro to Loops 1.General Knowledge 2.Two Types of Loops 3.The WHILE loop 1.
5b – For Loops Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.
Chapter 7: Repetition Structure (Loop) Department of Computer Science Foundation Year Program Umm Alqura University, Makkah Computer Programming Skills.
Fourth Quarter.  Involves loops or cycles ◦ Loops: means that a process may be repeated as long as certain condition remains true or remains false. ◦
9d. Pie Charts CSCI N207 Data Analysis Using Spreadsheet Department of Computer and Information Science, IUPUI Lingma Acheson
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
Chapter Looping 5. The Increment and Decrement Operators 5.1.
Loop Blocks Chapter 6 Part A. Program Blocks 1.Actions- commands, messages, methods 2.Branches- decisions to be made 3.Loops- actions to be repeated.
Control Structures WHILE Statement Looping. S E Q C E N U E REPITITION …a step or sequence of steps that are repeated until some condition is satisfied.
Learning Javascript From Mr Saem
Chapter 6 Controlling Program Flow with Looping Structures.
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.
UNIT 5 Lesson 15 Looping.
Tutorial 12 Working with Arrays, Loops, and Conditional Statements
Tutorial 10 – Class Average Application Introducing the Do…Loop While and Do…Loop Until Repetition Statements Outline Test-Driving the Class Average.
Chapter 5: Loops and Files.
Introducing Do While & Do Until Loops & Repetition Statements
Chapter 6 – Repetition 6.1 Do Loops 6.2 For...Next Loops
LESSON 11 – WHILE LOOPS UNIT 5 – 1/10/17.
Chapter 4 LOOPS © Bobby Hoggard, Department of Computer Science, East Carolina University / These slides may not be used or duplicated without permission.
Loop Control Structure.
حلقات التكرار.
Chapter (3) - Looping Questions.
Iteration: Beyond the Basic PERFORM
Algorithms Take a look at the worksheet. What do we already know, and what will we have to learn in this term?
Module 4 Loops.
Programming Concepts and Database
2g – ComboBox Lingma Acheson CSCI N331 VB .NET Programming
The structure of programming
7 – Variables, Input and Output
Chapter 13 Conditional Repetition
How to allow the program to know when to stop a loop.
4a- If And Else Lingma Acheson CSCI N331 VB .NET Programming
Presentation transcript:

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

ListBox Revisit ListBox – Allow users to view and select multiple items in a list. Camel Notation – lstXxxx Mainly used for displaying output in our class. Add items to the ListBox: lstXxxx.Items.Add(…) Each time an item is added, it will appear in the next line. Clear a ListBox – lstXxxx.Items.Clear() A ListBox should be large enough to display all of its content or to allow scroll-bars to be used easily

Loops Sometimes we need to repeat a certain action many times. E.g. Add a line of “***********************” into the ListBox. lstXxxx.Items.Add(“************************”) If we want to add three lines of the above altogether, we will need to write the above statement three times. The loop structure makes it possible to execute one piece of code repeatedly so we don’t need to write the same line of code again and again.

Loops – Do While The piece of code will be repeated until a certain condition is met. Do While Loop – Do While (condition is true) Block of codes Loop –Keep executing the Block of codes while the condition is true. –Stop executing when the condition becomes false. –The condition must become false at certain point so the loop can stop. Otherwise an infinite loop will occur.

Loops – Do While –E.g. Dim intCounter As Integer = 1 Do While intCounter < 4 lstOutput.Items.Add(“****************************”) intCounter = intCounter + 1 Loop Note: The intCounter has to increase by one each time to keep track how many times the line has been added. If not, intCounter will always be 1 and the condition is always true.

Loops – Do Until 6 Do Until Loop – Do Until (condition becomes true) Block of codes Loop –Keep executing the Block of codes when the condition is false. –Stop executing when the condition becomes true. –The condition must become true at certain point so the loop can stop. Otherwise an infinite loop will occur.

Loops – Do Until 7 Do Until Loop – Do Until (condition becomes true) Block of codes Loop –Keep executing the Block of codes when the condition is false. –Stop executing when the condition becomes true. –The condition must become true at certain point so the loop can stop. Otherwise an infinite loop will occur.

Loops 8 It is also possible for a Do While or Do Until Loop code block never gets executed. –E.g. Dim intCounter As Integer = 0 Do While intCounter > 10 lstOutput.Items.Add(“****************************”) intCounter = intCounter + 1 Loop