1 Principles of Software Design and Development LOOPS / REPITITION.

Slides:



Advertisements
Similar presentations
Looping Structures: Do Loops
Advertisements

Do-while Loops Programming. COMP102 Prog Fundamentals I: do-while Loops /Slide 2 The do-while Statement l Syntax do action while (condition) l How it.
Chapter 6: The Repetition Structure
1 PHP Statement Constructs Server Scripting. 5-2 Basic Statement All Statements end in a semicolon. Statements are delimited from the HTML code by enclosing.
Repeating Actions While and For Loops
Iteration (Looping Constructs in VB) Iteration: Groups of statements which are repeatedly executed until a certain test is satisfied Carrying out Iteration.
Iteration (Looping Constructs in VB) Iteration: Groups of statements which are repeatedly executed until a certain test is satisfied Carrying out Iteration.
CP Week 6 Repetition. Aims and Objectives zUnderstand what loops are and why they are needed zUnderstand the FOR loop used in programming zUnderstand.
Introduction to Computing Dr. Nadeem A Khan. Lecture 24.
ECE122 L11: For loops and Arrays March 8, 2007 ECE 122 Engineering Problem Solving with Java Lecture 11 For Loops and Arrays.
CS1061: C Programming Lecture 8: Repetition A. O’Riordan, 2004.
For Next Looping My first Looping Structure. For…Next FOR counter_variable = initial_value TO end_value STEP increment Statement-1 Statement-2 ……. Statement-n.
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.
For…Next : Nested Loop X= 0 For i = 0 To 4 For j = 0 To i-1 X=X+(i+j-1) Next j Next i How many times the inner loop is executed? What is x at the end of.
Presented by Lee Zenke 2015 Java Programming PT. 2.
1 Spreadsheets SELECTION. 2 Aims  Understand the principles of selection in Excel  Examine the basic IF statement format  Look into Nested IF statements.
Repetition Statements Repeating an Action A specified number of times While a Condition is True Until a Condition is True.
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.
1 CC111 Lec9 : Visual Basic Visual Basic (3) Lecture 9.
Chapter 6 - VB 2005 by Schneider1 Chapter 6 – Repetition 6.1 Do While and Do Until Loops 6.2 Processing Lists of Data with Do Loops 6.3 For...Next Loops.
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.
ME 142 Engineering Computation I Loops. Key Concepts Looping Basics For… Next Statement Do… Loop Statement For Each… Next Statement.
1 Week 6 The Repetition Structure. 2 The Repetition Structure (Looping) Lesson A Objectives After completing this lesson, you will be able to:  Code.
Chapter 5: Control Structures: Iteration Visual Basic.NET Programming: From Problem Analysis to Program Design.
Statements That Repeat. For...Next Loop Structure For counter = start To end Step increment statements Next counter Where Counter is tested to see if.
COMPUTER PROGRAMMING I 5.05 Apply Looping Structures.
CSC 162 Visual Basic I Programming. Repetition Structures Pretest Loop –Exit condition is tested before the body of code is executed Posttest Loop –Exit.
Tutorial 6 The Repetition Structure
Chapter 4 Looping Statements Adapted From: Starting Out with Visual Basic 2008 (Pearson)
Visual Basic.net Loops. Used to do multiple executions of the same block of code Do while loops Do until loops For next loops.
Lab 4 Range Review, Control Logic and Loops ► Range Review ► Control Logic and Loops ► Exercise.
Counter-Controlled Loops CSIS 1595: Fundamentals of Programming and Problem Solving 1.
Adding 10 items to a list… lstTest.Items.Add(1) lstTest.Items.Add(2) lstTest.Items.Add(3) lstTest.Items.Add(4) lstTest.Items.Add(5) lstTest.Items.Add(6)
6.2 For…Next Loops General Form of a For…Next Loop
Chapter 7 P 1 Lists and Loops List boxes and combo boxes List box - list of items - useful for a list which does not change Combo box - list of items -
Chapter 5: Control Structures: Iteration Visual Basic.NET Programming: From Problem Analysis to Program Design.
CW-V1 SDD 0901 Principals of Software Design and Development Loops Starter: Water JugsWater Jugs.
Counting Loops.
Looping Structures Do Loops, For Next Do...Loop While structures check the condition after executing the code and repeat a code block until the test.
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
Tutorial 6: The Repetition Structure1 Tutorial 6 The Repetition Structure.
For…Next and Do...While Loops! Happy St. Patrick’s Day!
Controlling Program Flow with Looping Structures
Topic: Control Statements. Recap of Sequence Control Structure Write a program that accepts the basic salary and allowance amount for an employee and.
Lab 6 (1) Range Review, Control Logic and Loops ► Control Logic and Loops ► Exercise.
National Diploma Unit 4 Introduction to Software Development Data Structures – Loops and selection.
FOR LOOPS "LOOP FOR A SET NUMBER OF TIMES.". FOR ( START_VALUE; END_VALUE; INCREMENT_NUMBER ) { //YOUR_CODE_HERE } So after the word "for" (in lowercase)
Dani Vainstein1 VBScript Session 5. Dani Vainstein2 What we learn last session? Branching Branching using If … Then … Else statement. Branching using.
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.
COMPUTER PROGRAMMING I 5.05 Apply Looping Structures.
Loops ISYS 350. Write a Program that asks user to enter any numbers and displays the largest number Process: Largest = the first number Get the next number.
Conditional Statements A conditional statement lets us choose which statement will be executed next Conditional statements give us the power to make basic.
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.
CE En 270 Brigham Young University Norm Jones
Clearly Visual Basic: Programming with Visual Basic nd Edition
Problem Solving and Control Statements: Part 2
Lists, Loops, Validation, and More
Counted Loops.
Introducing Do While & Do Until Loops & Repetition Statements
الحلقات التكرارية وجمل الدوران (loops)
حلقات التكرار.
Chapter 9 Control Structures.
Chapter (3) - Looping Questions.
Higher Computing Using Loops.
Case & Repetitive Statements
A LESSON IN LOOPING What is a loop?
Conditional Loops Counted Loops
Types of loops definite loop: A loop that executes a known number of times. Examples: Repeat these statements 10 times. Repeat these statements k times.
For...Next Statements.
Presentation transcript:

1 Principles of Software Design and Development LOOPS / REPITITION

2 Aims  Recap the use of loops – While & Do  Look at the format of the For…Next Loop  How can we use the For loop?  The use of STEP  Questions

RECAP Dim Counter as Integer Counter = 1 Do While Counter < 10 Counter = Counter + 1 Loop Dim Counter as Integer Counter = 1 Do Counter = Counter + 1 Loop Until Counter > 10

Btec National - Principles of Software Development 4 The For…Next Loop For the loop to work we need to know three things…  When the loop will start.  When the loop will end.  Where the loop is up to at a given point. Washing the dishes… Dim TotalNoOfDishes as Integer Dim CurrentDishNo as Integer TotalNoOfDishes = 10 For CurrentDishNo = 1 To TotalNoOfDishes ‘wash a dish Next

Btec National - Principles of Software Development 5 The For…Next Loop  The basic syntax for a ‘For loop’ is:   For = To  For = To  ‘Execute code statements  Next  Next

Btec National - Principles of Software Development 6 The For…Next Loop  Dim valFrom As Integer = txtFrom.Text  Dim valTo As Integer = txtTo.Text  Dim count As Integer  For count = valFrom To valTo  lstTest.Items.Add(count)  Next

The Use of STEP For Counter = 1 to 5 Step 2 'code here Next Would loop three times, through the values 1, 3 and 5. Step forces the loop (in this example) to make increments of 2. What does the following code do?... For Counter = 5 to 1 Step -1 'code here Next

Questions 1.Complete the code for the following For Next loop so that it starts with a value of 1 and ends with 10: Dim Counter as Integer For Counter = _____ To _____ 'code here Next

Questions What will be the value of Temp? Dim StartValue As Integer Dim StartValue As Integer Dim EndValue As Integer Dim EndValue As Integer Dim Counter As Integer Dim Counter As Integer Dim Temp As Integer Dim Temp As Integer StartValue = 10 StartValue = 10 EndValue = StartValue * 2 EndValue = StartValue * 2 Temp = 0 Temp = 0 For Counter = StartValue To EndValue For Counter = StartValue To EndValue Temp = Temp + 1 Temp = Temp + 1 Next Next

Questions  3. Write a For Next Loop that counts from 50 to 200.  4. Write a For Next Loop that counts from 10 to 0 in steps of 2