Repetition Structures
|
|
- Reginald Casey
- 6 years ago
- Views:
Transcription
1 Repetition Structures There are three main structures used in programming: sequential, decision and repetition structures. Sequential structures follow one line of code after another. Decision structures follow code based on conditions. Programmers use the repetition structure (also called looping or iteration structure) to instruct the computer to repeat one or more instructions, either a specified number of times OR until a condition (known as the loop condition) is met. Within the repetition structures there are three forms: For Next, Do While and Do Until. Although any of the three forms of repetition structure can be used to repeat instructions a specified number of times, the For Next loop is usually used in these situations as it requires less coding. The FOR NEXT Loop Syntax: The For Next loop takes the form: For counter = startvalue To endvalue Step stepvalue statements Next counter The For Next loop (or automatic counter loop) repeats one or more statements a specified number of times. notice that the syntax begins with the FOR statement and ends with the Next statement counter is the name of a numeric variable that keeps track of the number of times the loop is processed the startvalue, endvalue and stepvalue items control how many times to process the loop startvalue tells the loop where to begin stopvalue tells the loop where to stop stepvalue determines how much to add to (or subtract from) the counter each time loop is processed if Step and stepvalue are omitted, then VB uses a value of +1 The For Next loop performs the following 3 tasks 1. The loop initializes the counter to the startvalue. This is done just once at the beginning. 2. If stepvalue is positive, the loop checks to see if counter is greater than endvalue (if stepvalue negative then loop checks if counter less than endvalue). If it is, the loop stops, if not, then the loop statements are processed.
2 3. The loop adds the stepvalue onto the counter and repeats steps 1-2 until counter is greater than (or less than if stepvalue is negative) endvalue. In the example below the variable intcount is the counter, the startvalue is 1, the endvalue is 20 and the stepvalue is +1 For intcount = 1 to 20 txtcounter.text = intcount Next intcount Start Declare intcount variable for counter The For Next loop is represented in the flowchart by a hexagon. Four values are recorded inside the hexagon: the name of the counter, the startvalue, endvalue and stepvalue. Note that the endvalue is preceded by a > (greater than sign) intcount 1 >20 1 display intcount Stop The loop initializes the counter (intcount) to the startvalue 1. Loop then compares the current value of the counter to the end value. While every value of counter is less than 20, the loop continues and prints value of intcount. Finally the loop increments the counter by the step value 1, then the program flow loops back
3 Counters and Accumulators Counters are often required in algorithms to keep track of the number of times a user does something, such as the number of times a mark is entered in order to calculate an average. Counters are variables that are incremented by a constant value. The statement for incrementing or updating a counter takes the form: counter = counter + constant In an assignment statement, the expression on the right side of the equals sign is evaluated first and is then assigned to the variable on the left hand side. This makes it possible to use the current value of counter in the expression itself. Example intcounter = intcounter + 1 The above increments counter by + 1 each time statement executed A counter should be initialized when it is declared as a static variable, thus it will only be initialized once. Accumulators are useful for keeping a running total or sum of values, such as the total dollar value of items purchased. Accumulators are incremented by changing amounts. The statement for incrementing or updating an accumulator takes the form: accumulator= accumulator + value Example: sngtotal = sngtotal + sngitemcost The above adds value of sngitemcost to sngtotal each time the statement is executed
4 Lab #9 ~ Factorials The factorial of a number is the product of all the positive integers from 1 to the number. For example, 3 factorial, written as 3! = 3*2*1 = 6. Create an application using a For Next loop to compute the factorial of a number. Interface Form frmfactorial Factorial Calculator Label lblenternumber Enter A Number Text Box txtnumber Button cmdcalculate Calculate Factorial Label Label lblfactorialmessage lblfactorial Variables o Number o Factorial o Counter - integer entered by the user - integer result -integer to keep track of loop counter to number. Flowchart Start Get the number from the user. intcounter 1 >Number 1 Factorial = factorial *intcounter Display factorial End What does the pseudocode look like?
5 Code: Factorial Calculator written by your computer teacher, this day updated by you, today Public Class frmfactorial ***************************** Calculates the factorial based on the number enetered by the user. post: The factorial is shown in a label. Private Sub cmdcalculatefactorial_click(byval sender As System.Object, ByVal e As System.EventArgs) Handles cmdcalculatefactorial.click variables declared - only used within this procedure Dim intnumber As Integer Dim intfactorial As Integer Dim intcounter As Integer intnumber = Val(txtNumber.Text) get number from user intfactorial = 1 factorial must be initialized to one (otherwise multiply by zero) For intcounter = 1 To intnumber intfactorial = intfactorial * intcounter Next intcounter lblmessage.text = "Factorial is: " lblfactorialresult.text = intfactorial ***************************** Resets the labels for the answer so that when the user enters a new number, the result is cleared. post: The labels for the answers are cleared. Private Sub txtnumber_textchanged(byval sender As System.Object, ByVal e As System.EventArgs) Handles txtnumber.textchanged lblmessage.text = Nothing lblfactorialresult = Nothing End Class Save often as you work through this lab and test that your program works.
6 The Do While and the Do Until Loops When it is not known exactly how many times the loop will be required to repeat a set of instructions, then a Do While loop or Do until loop must be used. Both loops require a condition which often contains variables, mathematical, relational or logical operators. Just like the condition in an If Then Else statement, the loop condition must also evaluate to True or false. The condition determines if the loops statements or will be executed. Syntax: The Do While loop takes the form: Do While condition statements Loop Syntax: The Do Until loop takes the form: Do statements Loop until condition The Do While loop repeats one or more statements while a condition is true. The Do While loop begins with the Do While statement and ends with the Loop statement. The condition is located at the start of the loop and loop statements are only executed if the condition evaluates to True. If the condition evaluates to False, then the statements are not executed. Programmers call the Do While loop a pre-test loop as the loop tests the condition before executing any statements in the loop. Depending on how the condition evaluates, the statements in a Do While loop may not be executed at all. The Do Until loop repeats one or more statements until a condition becomes true. The Do Until loop begins with the Do statement and ends with the Loop Until statement. The condition is located at the end of the loop and loop statements are only executed if the condition evaluates to False. If the condition evaluates to True, then the statements are not executed again. Programmers call the Do Until loop a post-test loop as the loop tests the condition only after executing the statements in the loop. The statements then in a Do Until loop are always executed at least once.
7 Examples: Dim intcount as integer intcount = 1 Do While intcount <= 3 Print intcount intcount = intcount + 1 Loop Dim intcount as integer intcount = 1 Do Print intcount intcount = intcount + 1 Loop Until intcount > 3 Lab # 10 ~ Average Scores The average of a set of scores is calculated by dividing the sum of the scores by the number of scores. Use one text box to enable user to enter as many scores as they would like, until a -1 is entered. The text box should be disabled until the user clicks the Enter Scores button. The form should look as follows, with the following control names and text: Form frmaveragescore Average Score Calculator labels lblinformation Select Enter Scores lblnumberscores lblaveragemessage lblaverage lblsumofscores # of Scores The Average is: Average Sum of Scores Buttons cmdenterscores Enter Scores cmdaveragescore Average Score Variables Number of scores integer, declared globally Sum of scores integer to represent the total of the scores entered tempscore string that represents the entered value new score to represent the value of the temp score FLAG constant to represent -1 (entered to indicate the end of the scores
8 Pseudocode: cmdenterscores_click Prompt user to enter score Do while entered score is not equal to Nothing and the score is not equal to -1 Increment counter by 1 Score = value of entered score Add score to sum of scores Prompt user for next score Loop Show sum of scores Show number of scores that have been entered cmdaveragescores If the number of scores = 0, then Average = 0 Else Average = sum of scores entered / number of scored entered Display the average in the label. End if
9 Code: Average Score Calculator written by your computer teacher, this day updated by you, today Users enter scores in Input Boxes and an entry of -1 terminates entering scores. Public Class frmaveragescores global variables Dim intnumberofscores As Integer Dim intsumofscores As Integer ******************************** Gets the scores from the user in the form of input boxes. -1 is entered to indicate the end of entered scores. post: sum of the scores and the number of scores entered Private Sub cmdenterscores_click(byval sender As System.Object, ByVal e As System.EventArgs) Handles cmdenterscores.click Const FLAG As Integer = -1 Dim strtempscore As String Dim intnewscore As Integer lblaverage.text = Nothing lblnumberofscores.text = 0 get scores strtempscore = InputBox("Enter a score [ -1 to stop]", "Scores") Do While strtempscore <> Nothing And Val(strTempScore) <> -1 intnewscore = Val(strTempScore) intnumberofscores = intnumberofscores + 1 intsumofscores = intsumofscores + intnewscore strtempscore = InputBox("Enter a score [ -1 to stop]", "Scores") Loop lblsumofscores.text = intsumofscores lblnumberofscores.text = intnumberofscores ******************************** Calculates the average of entered scores pre: the number of scores and the sum of the scores entered post: the average is displayed for the user Private Sub cmdaveragescore_click(byval sender As System.Object, ByVal e As System.EventArgs) Handles cmdaveragescore.click Dim sngaverage As Single
10 If intnumberofscores > 0 Then sngaverage = intsumofscores / intnumberofscores lblaverage.text = sngaverage Else lblaverage.text = 0 End If End Class Save often as you work through this lab and test that your program works.
11 Lab #11 ~ Fibonacci Sequence A Fibonacci sequence is a sequence of numbers that is generated from 2 starting values called seeds. The 2 seeds are the first 2 numbers in the sequence. The seeds are then added together to generate the third number in the sequence. Each additional number is created by adding the 2 previous numbers. For example if the 2 seeds are 1 and 1, then the sequence is 1, 1, 2, 3, 5, 8 while seeds of 3 and 6 will generate 3, 6, 9, 15, 24 Create an application that gets 2 seed values from the user that will generate a Fibonacci sequence of 50 numbers. To display such a long series of numbers you should use a textbox rather than a label. Use the Textbox properties below to display the sequence. Dock setting dock to bottom sizes textbox so bottom right and left borders are anchored to the form ReadOnly set to True when textbox used to display info, user cannot type into it Multiline set to true to display multiple lines WordWrap set to true to wrap lines of text Scrollbars set to vertical to allow vertical scrolling The Form should look as follows with the property changes listed: Form frmfibonacci Fibonacci Sequence Builder Labels lblfirstnumber First Number Text Boxes txtfirstnumber txtsecondnumber lblsecondnumber lblinformation lblfibonaccisequence Second Number Enter two numbers Fibonacci Sequence txtsequence Button cmdgenerate Generate Sequence
12 One possible solution is: Code: Fibonacci Sequence Calculator written by your computer teacher, this day updated by you, today Users enters two numbers and a Fibonacci like sequence is generated from these numbers and displayed for the user. Public Class frmfibonacci Generates the list of numbers based on two entered post: Fibonacci like sequence displayed if two numbers are entered. Private Sub cmdgenerate_click(byval sender As System.Object, ByVal e As System.EventArgs) Handles cmdgenerate.click variables Dim lngfirstnumber As Long Long used otherwise overflow error Dim lngsecondnumber As Long Dim intcounter As Integer Dim lngnextnumber As Long End If End Class If txtfirstnumber.text = Nothing Or txtsecondnumber.text = Nothing Then MessageBox.Show("You must enter two numbers", "Two Numbers Required") Else lngfirstnumber = Val(txtFirstNumber.Text) lngsecondnumber = Val(txtSecondNumber.Text) txtsequence.text = lngfirstnumber & ", " & lngsecondnumber loop to generate next 48 numbers in sequence For intcounter = 3 To 50 lngnextnumber = lngfirstnumber + lngsecondnumber lngfirstnumber = lngsecondnumber lngsecondnumber = lngnextnumber txtsequence.text = txtsequence.text & ", " & lngnextnumber Next intcounter Can you think of another? Infinite Loops Logic errors can lead to infinite loops. If the program stops responding (cannot click on anything), right-clicking on the Windows Taskbar and selecting Close from the menu, and then select Close the Program to end the application.
Repetition Structures
Repetition Structures Chapter 5 Fall 2016, CSUS Introduction to Repetition Structures Chapter 5.1 1 Introduction to Repetition Structures A repetition structure causes a statement or set of statements
More informationCondition-Controlled Loop. Condition-Controlled Loop. If Statement. Various Forms. Conditional-Controlled Loop. Loop Caution.
Repetition Structures Introduction to Repetition Structures Chapter 5 Spring 2016, CSUS Chapter 5.1 Introduction to Repetition Structures The Problems with Duplicate Code A repetition structure causes
More informationUnit 7. Lesson 7.1. Loop. For Next Statements. Introduction. Loop
Loop Unit 7 Loop Introduction So far we have seen that each instruction is executed once and once only. Some time we may require that a group of instructions be executed repeatedly, until some logical
More informationIteration Loops. The Do While Loop (Continued) Looping Subtasks
Iteration s The Do While (Continued) ing Subtasks This section in your book is from pages 2 to. You might think that, since this in the Do While loop section, it only refers to those kinds of loops. This
More informationMicrosoft Visual Basic 2005: Reloaded
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 5 Repeating Program Instructions Objectives After studying this chapter, you should be able to: Include the repetition structure in pseudocode
More informationREPETITION CONTROL STRUCTURE LOGO
CSC 128: FUNDAMENTALS OF COMPUTER PROBLEM SOLVING REPETITION CONTROL STRUCTURE 1 Contents 1 Introduction 2 for loop 3 while loop 4 do while loop 2 Introduction It is used when a statement or a block of
More informationDecision Structures. Start. Do I have a test in morning? Study for test. Watch TV tonight. Stop
Decision Structures In the programs created thus far, Visual Basic reads and processes each of the procedure instructions in turn, one after the other. This is known as sequential processing or as the
More informationChapter 8. Arrays and More Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of
Chapter 8 Arrays and More Addison Wesley is an imprint of 2011 Pearson Addison-Wesley. All rights reserved. Introduction Arrays are like groups of variables that allow you to store sets of similar data
More informationTo enter the number in decimals Label 1 To show total. Text:...
Visual Basic tutorial - currency converter We will use visual studio to create a currency converter where we can convert a UK currency pound to other currencies. This is the interface for the application.
More informationYear 12 : Visual Basic Tutorial.
Year 12 : Visual Basic Tutorial. STUDY THIS Input and Output (Text Boxes) The three stages of a computer process Input Processing Output Data is usually input using TextBoxes. [1] Create a new Windows
More informationMr.Khaled Anwar ( )
The Rnd() function generates random numbers. Every time Rnd() is executed, it returns a different random fraction (greater than or equal to 0 and less than 1). If you end execution and run the program
More informationTutorial 03 understanding controls : buttons, text boxes
Learning VB.Net Tutorial 03 understanding controls : buttons, text boxes Hello everyone welcome to vb.net tutorials. These are going to be very basic tutorials about using the language to create simple
More informationProgramming Language 2 (PL2)
Programming Language 2 (PL2) 337.3.1 Illustrate the logical flow of program in sequence, selection and iteration structure 337.3.2 Apply selection and repetitive structure Repetition structure (or loop):
More informationIntroduction To Programming. Chapter 5: Arrays and More
Introduction To Programming Chapter 5: Arrays and More Introduction Arrays are like groups of variables that allow you to store sets of similar data A single dimension array is useful for storing and working
More informationVB FUNCTIONS AND OPERATORS
VB FUNCTIONS AND OPERATORS In der to compute inputs from users and generate results, we need to use various mathematical operats. In Visual Basic, other than the addition (+) and subtraction (-), the symbols
More informationIn this tutorial we will create a simple calculator to Add/Subtract/Multiply and Divide two numbers and show a simple message box result.
Simple Calculator In this tutorial we will create a simple calculator to Add/Subtract/Multiply and Divide two numbers and show a simple message box result. Let s get started First create a new Visual Basic
More informationReview. October 20, 2006
Review October 20, 2006 1 A Gentle Introduction to Programming A Program (aka project, application, solution) At a very general level there are 3 steps to program development Determine output Determine
More informationComputer Programming. Basic Control Flow - Loops. Adapted from C++ for Everyone and Big C++ by Cay Horstmann, John Wiley & Sons
Computer Programming Basic Control Flow - Loops Adapted from C++ for Everyone and Big C++ by Cay Horstmann, John Wiley & Sons Objectives To learn about the three types of loops: while for do To avoid infinite
More informationCopyright 2014 Pearson Education, Inc. Chapter 5. Lists and Loops. Copyright 2014 Pearson Education, Inc.
Chapter 5 Lists and Loops Topics 5.1 Input Boxes 5.2 List Boxes 5.3 Introduction to Loops: The Do While Loop 5.4 The Do Until and For Next Loops 5.5 Nested Loops 5.6 Multicolumn List Boxes, Checked List
More informationECE 122. Engineering Problem Solving with Java
ECE 122 Engineering Problem Solving with Java Lecture 10 For Loops and Arrays Outline Problem: How can I perform the same operations a fixed number of times? Considering for loops Performs same operations
More informationRepetition. October 4, Chapter 6 - VB 2005 by Schneider 1
Repetition October 4, 2006 Chapter 6 - VB 2005 by Schneider 1 Chapter 6 Repetition 6.1 Do Loops 6.2 Processing Lists of Data with Do Loops 6.3 For...Next Loops 6.4 A Case Study: Analyze a Loan Chapter
More informationYou will have mastered the material in this chapter when you can:
CHAPTER 6 Loop Structures OBJECTIVES You will have mastered the material in this chapter when you can: Add a MenuStrip object Use the InputBox function Display data using the ListBox object Understand
More informationDEVELOPING OBJECT ORIENTED APPLICATIONS
DEVELOPING OBJECT ORIENTED APPLICATIONS By now, everybody should be comfortable using form controls, their properties, along with methods and events of the form class. In this unit, we discuss creating
More informationLoops / Repetition Statements
Loops / Repetition Statements Repetition statements allow us to execute a statement multiple times Often they are referred to as loops C has three kinds of repetition statements: the while loop the for
More informationSNS COLLEGE OF ENGINEERING
SNS COLLEGE OF ENGINEERING DEPARTMENT OF CSE Presented By Thillaiarasu.N SCRAMBLE 2 Solution 3 What is Pseudocode? 4 Consists of: Short Readable Formally styled English language Used for: Explaining the
More informationLearning VB.Net. Tutorial 10 Collections
Learning VB.Net Tutorial 10 Collections Hello everyone welcome to vb.net tutorials. These are going to be very basic tutorials about using the language to create simple applications, hope you enjoy it.
More information3. Can every Do-Loop loop be written as a For-Next loop? Why or why not? 4. Name two types of files that can be opened and used in a VB program.
CE 311 K Fall 005 Second Exam - Examples Answers at the bottom. 1. What are two categories of flow control structures?. Name three logical operators in Visual Basic (VB). 3. Can every Do-Loop loop be written
More informationVARIABLES. 1. STRINGS Data with letters and/or characters 2. INTEGERS Numbers without decimals 3. FLOATING POINT NUMBERS Numbers with decimals
VARIABLES WHAT IS A VARIABLE? A variable is a storage location in the computer s memory, used for holding information while the program is running. The information that is stored in a variable may change,
More informationSNS COLLEGE OF ENGINEERING,
SNS COLLEGE OF ENGINEERING, COIMBATORE Department of Computer Science and Engineering QUESTION BANK(PART A) GE8151 - PROBLEM SOLVING AND PYTHON PROGRAMMING TWO MARKS UNIT-I 1. What is computer? Computers
More information5.1. Chapter 5: The Increment and Decrement Operators. The Increment and Decrement Operators. Looping. ++ is the increment operator.
Chapter 5: Looping 5.1 The Increment and Decrement Operators Copyright 2009 Pearson Education, Inc. Copyright Publishing as Pearson 2009 Addison-Wesley Pearson Education, Inc. Publishing as Pearson Addison-Wesley
More informationLearning VB.Net. Tutorial 19 Classes and Inheritance
Learning VB.Net Tutorial 19 Classes and Inheritance Hello everyone welcome to vb.net tutorials. These are going to be very basic tutorials about using the language to create simple applications, hope you
More information*Starting Out with C++: From Control Structures through Objects, 7/E* by *Tony Gaddis* COMPUTER PROGRAMMING LECTURE 05 LOOPS IMRAN IHSAN
PowerPoint Slides adapted from *Starting Out with C++: From Control Structures through Objects, 7/E* by *Tony Gaddis* Copyright 2012 Pearson Education Inc. COMPUTER PROGRAMMING LECTURE 05 LOOPS IMRAN IHSAN
More informationC4.3, 4 Lab: Conditionals - Select Statement and Additional Input Controls Solutions
C4.3, 4 Lab: Conditionals - Select Statement and Additional Input Controls Solutions Between the comments included with the code and the code itself, you shouldn t have any problems understanding what
More informationComputer Programming: C++
The Islamic University of Gaza Engineering Faculty Department of Computer Engineering Fall 2017 ECOM 2003 Muath i.alnabris Computer Programming: C++ Experiment #3 Loops Part I Contents Introduction For-Loop
More informationControl Structures II. Repetition (Loops)
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 to 100 The answer will be 1 + 2 + 3 + 4 + 5 + 6 + +
More informationCPE 112 Spring 2015 Exam II (100 pts) March 4, Definition Matching (8 Points)
Name Definition Matching (8 Points) 1. (8 pts) Match the words with their definitions. Choose the best definition for each word. Relational Expression Iteration Counter Count-controlled loop Loop Flow
More informationPROBLEM SOLVING WITH LOOPS. Chapter 7
PROBLEM SOLVING WITH LOOPS Chapter 7 Concept of Repetition Structure Logic It is a computer task, that is used for Repeating a series of instructions many times. Ex. The Process of calculating the Total
More informationLearning VB.Net. Tutorial 17 Classes
Learning VB.Net Tutorial 17 Classes Hello everyone welcome to vb.net tutorials. These are going to be very basic tutorials about using the language to create simple applications, hope you enjoy it. If
More informationMIS 216 SPRING 2018 PROJECT 4
MIS 216 SPRING 2018 PROJECT 4 Subs / Functions Arrays / Classes 1. Start a new project a. Create a folder on your desktop name it yourinitialsproject3 as in tnjproject3. b. FILE NEW PROJECT c. Change the
More informationThere are algorithms, however, that need to execute statements in some other kind of ordering depending on certain conditions.
Introduction In the programs that we have dealt with so far, all statements inside the main function were executed in sequence as they appeared, one after the other. This type of sequencing is adequate
More informationVisual Basic 2008 The programming part
Visual Basic 2008 The programming part Code Computer applications are built by giving instructions to the computer. In programming, the instructions are called statements, and all of the statements that
More informationIslamic University of Gaza Computer Engineering Dept. C++ Programming. For Industrial And Electrical Engineering By Instructor: Ruba A.
Islamic University of Gaza Computer Engineering Dept. C++ Programming For Industrial And Electrical Engineering By Instructor: Ruba A. Salamh Chapter Four: Loops 2 Chapter Goals To implement while, for
More informationLab 3 The High-Low Game
Lab 3 The High-Low Game LAB GOALS To develop a simple windows-based game named High-Low using VB.Net. You will use: Buttons, Textboxes, Labels, Dim, integer, arithmetic operations, conditionals [if-then-else],
More informationMaking Decisions and Working with Strings
GADDIS_CH04 12/16/08 6:47 PM Page 193 CHAPTER 4 Making Decisions and Working with Strings TOPICS 4.1 The Decision Structure 4.2 The If...Then Statement 4.3 The If...Then...Else Statement 4.4 The If...Then...ElseIf
More informationCSc Introduc/on to Compu/ng. Lecture 8 Edgardo Molina Fall 2011 City College of New York
CSc 10200 Introduc/on to Compu/ng Lecture 8 Edgardo Molina Fall 2011 City College of New York 18 The Null Statement Null statement Semicolon with nothing preceding it ; Do-nothing statement required for
More informationChapter 2B: Lists and Loops
Chapter 2B: Lists and Loops Introduction This chapter introduces: Input boxes List and combo boxes Loops Random numbers The ToolTip control Section 2B.1 Input Boxes Input boxes provide a simple way to
More informationRepetition and Loop Statements Chapter 5
Repetition and Loop Statements Chapter 5 1 Chapter Objectives To understand why repetition is an important control structure in programming To learn about loop control variables and the three steps needed
More informationJava Programming: Guided Learning with Early Objects Chapter 5 Control Structures II: Repetition
Java Programming: Guided Learning with Early Objects Chapter 5 Control Structures II: Repetition Learn about repetition (looping) control structures Explore how to construct and use: o Counter-controlled
More informationAPPM 2460: Week Three For, While and If s
APPM 2460: Week Three For, While and If s 1 Introduction Today we will learn a little more about programming. This time we will learn how to use for loops, while loops and if statements. 2 The For Loop
More informationChapter 5. Lists and Loops Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of
Chapter 5 Lists and Loops Addison Wesley is an imprint of 2011 Pearson Addison-Wesley. All rights reserved. Introduction This chapter introduces: Input boxes List and combo boxes Loops Random numbers The
More informationMore about Loops and Decisions
More about Loops and Decisions 5 In this chapter, we continue to explore the topic of repetition structures. We will discuss how loops are used in conjunction with the other control structures sequence
More informationISM 3253 Exam I Spring 2009
ISM 3253 Exam I Spring 2009 Directions: You have exactly 75 minutes to complete this test. Time available is part of the exam conditions and all work must cease when "Stop work" is announced. Failing to
More informationComputing Science Unit 1
Computing Science Unit 1 Software Design and Development Programming Practical Tasks Business Information Technology and Enterprise Contents Input Validation Find Min Find Max Linear Search Count Occurrences
More informationWhy Is Repetition Needed?
Why Is Repetition Needed? Repetition allows efficient use of variables. It lets you process many values using a small number of variables. For example, to add five numbers: Inefficient way: Declare a variable
More informationCondition Controlled Loops. Introduction to Programming - Python
+ Condition Controlled Loops Introduction to Programming - Python + Repetition Structures n Programmers commonly find that they need to write code that performs the same task over and over again + Example:
More informationLaboratory 5: Implementing Loops and Loop Control Strategies
Laboratory 5: Implementing Loops and Loop Control Strategies Overview: Objectives: C++ has three control structures that are designed exclusively for iteration: the while, for and do statements. In today's
More informationProgramming with Visual Studio Higher (v. 2013)
Programming with Visual Studio Higher (v. 2013) Contents/Requirements Checklist Multiple selection: using ifs & case While Loops Using arrays Filling arrays Displaying array contents Types of variables:
More informationFundamentals of Programming Session 13
Fundamentals of Programming Session 13 Instructor: Reza Entezari-Maleki Email: entezari@ce.sharif.edu 1 Fall 2014 These slides have been created using Deitel s slides Sharif University of Technology Outlines
More informationAnnouncements. Lab Friday, 1-2:30 and 3-4:30 in Boot your laptop and start Forte, if you brought your laptop
Announcements Lab Friday, 1-2:30 and 3-4:30 in 26-152 Boot your laptop and start Forte, if you brought your laptop Create an empty file called Lecture4 and create an empty main() method in a class: 1.00
More informationRepetition Structures Chapter 9
Sum of the terms Repetition Structures Chapter 9 1 Value of the Alternating Harmonic Series 0.9 0.8 0.7 0.6 0.5 10 0 10 1 10 2 10 3 Number of terms Objectives After studying this chapter you should be
More informationChapter 3 Structured Program Development
1 Chapter 3 Structured Program Development Copyright 2007 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 3 - Structured Program Development Outline 3.1 Introduction
More informationIntroduction to Scientific Computing
Introduction to Scientific Computing Dr Hanno Rein Last updated: October 12, 2018 1 Computers A computer is a machine which can perform a set of calculations. The purpose of this course is to give you
More informationMicrosoft Visual Basic 2015: Reloaded
Microsoft Visual Basic 2015: Reloaded Sixth Edition Chapter Seven More on the Repetition Structure Objectives After studying this chapter, you should be able to: Code a counter-controlled loop Nest repetition
More informationOver and Over Again GEEN163
Over and Over Again GEEN163 There is no harm in repeating a good thing. Plato Homework A programming assignment has been posted on Blackboard You have to convert three flowcharts into programs Upload the
More informationCMPT 110 MIDTERM OCTOBER 18, 2001
CMPT 110 MIDTERM OCTOBER 18, 2001 1 What will be displayed when the command button is clicked? 7% Level of difficulty 7 (out of 10) Assume there is a command button called cmdbutton Assume there is a picturebox
More informationChapter 3. More Flow of Control. Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Chapter 3 More Flow of Control Overview 3.1 Using Boolean Expressions 3.2 Multiway Branches 3.3 More about C++ Loop Statements 3.4 Designing Loops Slide 3-3 Flow Of Control Flow of control refers to the
More informationAn Introduction to Programming with C++ Sixth Edition. Chapter 7 The Repetition Structure
An Introduction to Programming with C++ Sixth Edition Chapter 7 The Repetition Structure Objectives Differentiate between a pretest loop and a posttest loop Include a pretest loop in pseudocode Include
More informationJava. Programming: Chapter Objectives. Why Is Repetition Needed? Chapter 5: Control Structures II. Program Design Including Data Structures
Chapter 5: Control Structures II Java Programming: Program Design Including Data Structures Chapter Objectives Learn about repetition (looping) control structures Explore how to construct and use count-controlled,
More informationIncrement and the While. Class 15
Increment and the While Class 15 Increment and Decrement Operators Increment and Decrement Increase or decrease a value by one, respectively. the most common operation in all of programming is to increment
More informationChapter 5: Control Structures II (Repetition) Objectives (cont d.) Objectives. while Looping (Repetition) Structure. Why Is Repetition Needed?
Chapter 5: Control Structures II (Repetition) Objectives In this chapter, you will: Learn about repetition (looping) control structures Explore how to construct and use countercontrolled, sentinel-controlled,
More informationCSCE150A. Introduction. While Loop. Compound Assignment. For Loop. Loop Design. Nested Loops. Do-While Loop. Programming Tips CSCE150A.
Chapter 5 While For 1 / 54 Computer Science & Engineering 150A Problem Solving Using Computers Lecture 05 - s Stephen Scott (Adapted from Christopher M. Bourke) Fall 2009 While For 2 / 54 5.1 Repetition
More informationOutline. Program development cycle. Algorithms development and representation. Examples.
Outline Program development cycle. Algorithms development and representation. Examples. 1 Program Development Cycle Program development cycle steps: Problem definition. Problem analysis (understanding).
More informationJava Programming: Guided Learning with Early Objects Chapter 5 Control Structures II: Repetition
Java Programming: Guided Learning with Early Objects Chapter 5 Control Structures II: Repetition Learn about repetition (looping) control structures Explore how to construct and use: o Counter-controlled
More informationChapter 5. Repetition. Contents. Introduction. Three Types of Program Control. Two Types of Repetition. Three Syntax Structures for Looping in C++
Repetition Contents 1 Repetition 1.1 Introduction 1.2 Three Types of Program Control Chapter 5 Introduction 1.3 Two Types of Repetition 1.4 Three Structures for Looping in C++ 1.5 The while Control Structure
More informationComputer Science & Engineering 150A Problem Solving Using Computers. Chapter 5. Repetition in Programs. Notes. Notes. Notes. Lecture 05 - Loops
Computer Science & Engineering 150A Problem Solving Using Computers Lecture 05 - Loops Stephen Scott (Adapted from Christopher M. Bourke) 1 / 1 Fall 2009 cbourke@cse.unl.edu Chapter 5 5.1 Repetition in
More informationQuick Reference Guide
SOFTWARE AND HARDWARE SOLUTIONS FOR THE EMBEDDED WORLD mikroelektronika Development tools - Books - Compilers Quick Reference Quick Reference Guide with EXAMPLES for Basic language This reference guide
More informationIntroduction. C provides two styles of flow control:
Introduction C provides two styles of flow control: Branching Looping Branching is deciding what actions to take and looping is deciding how many times to take a certain action. Branching constructs: if
More informationLooping Subtasks. We will examine some basic algorithms that use the while and if constructs. These subtasks include
1 Programming in C Looping Subtasks We will examine some basic algorithms that use the while and if constructs. These subtasks include Reading unknown quantity of data Counting things Accumulating (summing)
More informationUniversity of Technology. Laser & Optoelectronics Engineering Department. C++ Lab.
University of Technology Laser & Optoelectronics Engineering Department C++ Lab. Fifth week Control Structures A program is usually not limited to a linear sequence of instructions. During its process
More informationLecture 7 Tao Wang 1
Lecture 7 Tao Wang 1 Objectives In this chapter, you will learn about: Interactive loop break and continue do-while for loop Common programming errors Scientists, Third Edition 2 while Loops while statement
More informationVISUAL BASIC II CC111 INTRODUCTION TO COMPUTERS
VISUAL BASIC II CC111 INTRODUCTION TO COMPUTERS Intended Learning Objectives Able to build a simple Visual Basic Application. 2 The Sub Statement Private Sub ControlName_eventName(ByVal sender As System.Object,
More informationVISUAL BASIC 2005 EXPRESS: NOW PLAYING
VISUAL BASIC 2005 EXPRESS: NOW PLAYING by Wallace Wang San Francisco ADVANCED DATA STRUCTURES: QUEUES, STACKS, AND HASH TABLES Using a Queue To provide greater flexibility in storing information, Visual
More informationUnit 6 - Software Design and Development LESSON 3 KEY FEATURES
Unit 6 - Software Design and Development LESSON 3 KEY FEATURES Last session 1. Language generations. 2. Reasons why languages are used by organisations. 1. Proprietary or open source. 2. Features and tools.
More informationhttps://asd-pa.perfplusk12.com/admin/admin_curric_maps_display.aspx?m=5507&c=618&mo=18917&t=191&sy=2012&bl...
Page 1 of 13 Units: - All - Teacher: ProgIIIJavaI, CORE Course: ProgIIIJavaI Year: 2012-13 Intro to Java How is data stored by a computer system? What does a compiler do? What are the advantages of using
More informationC Programming for Engineers Structured Program
C Programming for Engineers Structured Program ICEN 360 Spring 2017 Prof. Dola Saha 1 Switch Statement Ø Used to select one of several alternatives Ø useful when the selection is based on the value of
More informationSTUDENT LESSON A12 Iterations
STUDENT LESSON A12 Iterations Java Curriculum for AP Computer Science, Student Lesson A12 1 STUDENT LESSON A12 Iterations INTRODUCTION: Solving problems on a computer very often requires a repetition of
More informationMultiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible)
Name Closed notes, book and neighbor. If you have any questions ask them. Notes: Segment of code necessary C++ statements to perform the action described not a complete program Program a complete C++ program
More informationVISUAL GUIDE to. RX Scripting. for Roulette Xtreme - System Designer 2.0. L J Howell UX Software Ver. 1.0
VISUAL GUIDE to RX Scripting for Roulette Xtreme - System Designer 2.0 L J Howell UX Software 2009 Ver. 1.0 TABLE OF CONTENTS INTRODUCTION...ii What is this book about?... iii How to use this book... iii
More informationMicrosoft Visual Basic 2015: Reloaded
Microsoft Visual Basic 2015: Reloaded Sixth Edition Chapter Three Memory Locations and Calculations Objectives After studying this chapter, you should be able to: Declare variables and named constants
More informationChapter 5: Loops and Files
Chapter 5: Loops and Files 5.1 The Increment and Decrement Operators The Increment and Decrement Operators ++ is the increment operator. It adds one to a variable. val++; is the same as val = val + 1;
More information11.3 Function Prototypes
11.3 Function Prototypes A Function Prototype contains the function s return type, name and parameter list Writing the function prototype is declaring the function. float square (float x); In a function
More informationUsing loops and debugging code
Using loops and debugging code Chapter 7 Looping your code pp. 103-118 Exercises 7A & 7B Chapter 8 Fixing Bugs pp. 119-132 Exercise 8 Chapter 7 Looping your code Coding a For loop Coding a Do loop Chapter
More informationChapter 5: Control Structures II (Repetition)
Chapter 5: Control Structures II (Repetition) 1 Objectives Learn about repetition (looping) control structures Explore how to construct and use count-controlled, sentinel-controlled, flag-controlled, and
More informationCOSC 122 Computer Fluency. Iteration and Arrays. Dr. Ramon Lawrence University of British Columbia Okanagan
COSC 122 Computer Fluency Iteration and Arrays Dr. Ramon Lawrence University of British Columbia Okanagan ramon.lawrence@ubc.ca Key Points 1) A loop repeats a set of statements multiple times until some
More informationLoops In Python. In this section of notes you will learn how to rerun parts of your program without having to duplicate the code.
Loops In Python In this section of notes you will learn how to rerun parts of your program without having to duplicate the code. The Need For Repetition (Loops) Writing out a simple counting program (1
More informationNonvisual Arrays and Recursion. by Chris Brown under Prof. Susan Rodger Duke University June 2012
Nonvisual Arrays and Recursion by Chris Brown under Prof. Susan Rodger Duke University June 2012 Nonvisual Arrays This tutorial will display how to create and use nonvisual arrays in Alice. Nonvisual arrays
More informationControl Statements. Objectives. ELEC 206 Prof. Siripong Potisuk
Control Statements ELEC 206 Prof. Siripong Potisuk 1 Objectives Learn how to change the flow of execution of a MATLAB program through some kind of a decision-making process within that program The program
More informationNumber System. Introduction. Natural Numbers (N) Whole Numbers (W) Integers (Z) Prime Numbers (P) Face Value. Place Value
1 Number System Introduction In this chapter, we will study about the number system and number line. We will also learn about the four fundamental operations on whole numbers and their properties. Natural
More informationChapter 5: Prefix vs. Postfix 8/19/2018. The Increment and Decrement Operators. Increment and Decrement Operators in Program 5-1
Chapter 5: Loops and Files The Increment and Decrement Operators ++ is the increment operator. It adds one to a variable. val++; is the same as val = val + 1; ++ can be used before (prefix) or after (postfix)
More informationJava Outline (Upto Exam 2)
Java Outline (Upto Exam 2) Part 4 IF s (Branches) and Loops Chapter 12/13 (The if Statement) Hand in Program Assignment#1 (12 marks): Create a program called Ifs that will do the following: 1. Ask the
More information