For Loops (ProjFor1, ProjFor2, ProjFor3, ProjFor4, textbox, textbox1) Please use speaker notes for additional information!

Slides:



Advertisements
Similar presentations
Chapter 6: The Repetition Structure
Advertisements

Microsoft Visual Basic: Reloaded Chapter Seven More on the Repetition Structure.
Practical Programming COMP153-08S Lecture: Repetition Continued.
Computer Science 1620 Loops.
1 Parts of a Loop (reminder) Every loop will always contain three main elements: –Priming: initialize your variables. –Testing: test against some known.
Copyright 2008 by Pearson Education 1 Building Java Programs Chapter 2 Lecture 2-2: The for Loop reading: 2.3 self-check: exercises: 2-14 videos:
CSI 101 Elements of Computing Spring 2009 Lecture # 8 Looping and Recursion Wednesday, February 25 th, 2009.
IS 1181 IS 118 Introduction to Development Tools VB Chapter 03.
Section 3 - Selection and Repetition Constructs. Control Structures 1. Sequence 2. Selection 3. Repetition.
Chapter 5 new The Do…Loop Statement
by Chris Brown under Prof. Susan Rodger Duke University June 2012
Making a Timer in Alice.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Interest Calculator Application Introducing the For...Next Repetition Statements.
Copyright 2009 by Pearson Education Building Java Programs Chapter 2 Lecture 2-2: The for Loop reading: 2.3 self-check: exercises: 2-14 videos: Ch.
Lecture Set 5 Control Structures Part D - Repetition with 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.
Array - adding to array at run time Please see speaker notes for additional information!
Quiz Answers 1. Show the output from the following code fragment: int a = 5, b = 2, c = 3; cout
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
Variety of JavaScript Examples Please use speaker notes for additional information!
1 BUILDING JAVA PROGRAMS CHAPTER 2 PRIMITIVE DATA AND DEFINITE LOOPS.
6.2 For…Next Loops General Form of a For…Next Loop
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.1.
SW388R6 Data Analysis and Computers I Slide 1 Percentiles and Standard Scores Sample Percentile Homework Problem Solving the Percentile Problem with SPSS.
1 Chapter 9. To familiarize you with  Simple PERFORM  How PERFORM statements are used for iteration  Options available with PERFORM 2.
You should unzip and download the beginning programs.
Copyright 2010 by Pearson Education 1 Building Java Programs Chapter 2 Lecture 2-2: The for Loop reading: 2.3 self-check: exercises: 2-14 videos:
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.
Copyright 2008 by Pearson Education 1 Building Java Programs Chapter 2 Lecture 2-2: The for Loop reading: 2.3 self-check: exercises: 2-14 videos:
Chapter 15 I’m on the Inside; You’re on the Outside (Nested Loops) Clearly Visual Basic: Programming with Visual Basic nd Edition.
Pay Example (PFirst98) Please use speaker notes for additional information!
Building Java Programs Chapter 2 Primitive Data and Definite Loops Copyright (c) Pearson All rights reserved.
Maximum Profit Please use speaker notes for additional information!
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 16 I’m on the Inside; You’re on the Outside.
31/01/ Selection If selection construct.
Iterations (aka Loops). 2 Loops Loops (iterations) are segments of code that may be executed several times. Fixed-count (definite) loops repeat a fixed.
© 2006 Lawrenceville Press Slide 1 Chapter 6 The Post-Test Do…Loop Statement  Loop structure that executes a set of statements as long as a condition.
Scrollbar1 The Scrollbar A final tool in the toolbox is the scrollbar. There are two of them, one ordered horizontally and the other vertically, both do.
Word Processor Version.01 EME 4411 Week 5. The Scroll Bars.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Student Grades Application Introducing Two-Dimensional Arrays and RadioButton.
Microsoft Visual Basic 2012 CHAPTER FOUR Variables and Arithmetic Operations.
 2002 Prentice Hall. All rights reserved. 1 Chapter 5 – Control Structures: Part 2 Outline 5.1Introduction 5.2 Essentials of Counter-Controlled Repetition.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 6 Looping and Multiple Forms.
© 2010 Lawrenceville Press Slide 1 Chapter 5 The Do…Loop Statement  Loop structure that executes a set of statements as long as a condition is true. 
This is a while loop. The code is done while the condition is true. The code that is done is enclosed in { }. Note that this program has three parts: Housekeeping.
3rd prep. – 2nd Term MOE Book Questions.
3rd prep. – 2nd Term MOE Book Questions.
Variables and Arithmetic Operations
Visual Basic.
Department Array in Visual Basic
Please use speaker notes for additional information!
Chapter (3) - Looping Questions.
Iteration: Beyond the Basic PERFORM
CIS 16 Application Development Programming with Visual Basic
Building Java Programs
Building Java Programs
the captured notes and redid - hopefully it all works.
Additional Topics in VB.NET
If statements (Inven1, Inven2, Inven2a, Inven3, Inven3a)
Building Java Programs
Providing an area on a PowerPoint slide that users can write into.
Building Java Programs
Building Java Programs
Building Java Programs
Building Java Programs
Building Java Programs
Building Java Programs
Chapter 2 Lecture 2-2: The for Loop reading: 2.3
More on If statements (Calculate, Calculate1, Calculate2)
This is an introduction to JavaScript using the examples found at the CIS17 website. In previous examples I specified language = Javascript, instead of.
Presentation transcript:

For Loops (ProjFor1, ProjFor2, ProjFor3, ProjFor4, textbox, textbox1) Please use speaker notes for additional information!

textbox Two areas are being used to show the results of clicking the Calculate button. The area on the left is a PictureBox and the area on the right is a TextBox.

textbox The logic in the cmdCalc has a For loop within a For loop. The logic and the syntax will be discussed in the next slides. & means concatenate. There are two very different ways of showing the data in a text box and in a picture box. picAns.Cls will clear out the picture box. The text box is set to “” to clear it. Properties for the text box include setting MultiLine to True to allow this output.

For Loop For ct = 1 To 5 answer = ct + ct Next ct This slide will show a simple example using a For loop. Note that the loop starts with the word For and the bottom of the loop is marked by the word Next. ctanswer ct is initialized at 1. When next is reached, ct is checked against the limit of 5 to determine if the loop should continue. If the loop should continue then ct is incremented by 1 for the next pass in the for loop. Initialize ct ct has reached 5 so processing ends. answer is calculate as ct + ct as seen inside the loop.

This slide will show a simple example using a nested For loop. Note that the loop each starts with the word For and the bottom of the loop is marked by the word Next. ct1 ct2answer ct1 is initialized at 1. ct2 is initialized at 1. answer is calculated. Next ct2 increments ct2 and goes back to the inner loop. When ct2 reaches 4, control drops through to next ct1. ct1 is incremented by 1 and the inner loop has ct2 reset to 1. Nested For Loop For ct1 = 1 To 5 For ct2 = 1 To 4 answer = ct1 + ct2 Next ct2 Next ct1 ct2 reaches maximum of 4 so ct1 is incremented by 1 and ct2 is reset to 1. ct1 and ct2 have both reached maximum so loop ends.

Dim ct1 As Integer, ct2 As Integer, ans As Integer For ct1 = 1 To 5 For ct2 = 1 To 5 ans = ct1 + ct2 txtAns.Text = txtAns.Text & ct1 & "+" & ct2 & "=" & ans & Chr(13) & Chr(10) picAns.Print ct1 & "+" & ct2 & "=" & ans Next ct2 Next ct1 textbox With the text box, additions to the table must be concatenated to what is already there. That is why you see txtAns.Text = txtAns.Text & etc.. I am concatenating what is already in the field with ct1 with the + with ct2 with the = with ans and then with the carriage control and line feed. With the picture box, I used the Print statement and simply coded the data to be printed. Note that ct1 is concatenated with the + which is concatenated with ct2 which is concatenated with the = which is concatenated with ans. Each new Print will show on a separate line.

textbox1 Note that I have no set up a scroll bar in the textbox so that I can scroll and see all of the data in the text box.

textbox1 When I click on ScrollBars and the down arrow, I see the options which are: 0-None, 1-Horizontal, 2-Vertical and 3-Both. For this example I only needed the vertical scroll bar. MultiLine is set to true - a requirement when you are going to add scroll bars.

ProjFor1 Note that I did not put the answer in a work area or variable, I simply coded X + X. In this example, I did not use concatenation. Instead I used the semi-colon to separate the components of the formula.

ProjFor2 The range for X is from 1 to 3 and the range for Y is from 1 to 4. X is set to 1. Y is set to 1. The inner FOR loop is processed with X = 1 and Y varying from 1 to 4. When Y would be greater than 4, the inner loop is done and control returns to the outer loop. X is incremented by 1 to make it 2. The the code drops through to the inner loop for a new set of passes. Because control is dropping through rather than returning to the FOR from the NEXT, The inner loop is starting fresh and Y is set to 1. The loop will stop when processing has been done for both X and Y at their maximums. That is when X= 3 and Y = 4 has been processed.

ProjFor3 In this example I am using Step so that X and Y are not incremented by the default of 1, but rather by the number specified in the Step.

ForProj4 In this example, I am using a negative step. Note that I started X at 8 and want to end when X = 2. The step is -2 so each time X is changed it will be reduced by 2. Y starts at 9 and Y will be decremented by 3 until it has been processed with a value of 3.