COM148X1 Interactive Programming Lecture 3. Topics Today String Functions Using Timer Looping.

Slides:



Advertisements
Similar presentations
String and Lists Dr. Benito Mendoza. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list List.
Advertisements

CS0004: Introduction to Programming Repetition – Do Loops.
Computer programming Lecture 3. Lecture 3: Outline Program Looping [Kochan – chap.5] –The for Statement –Relational Operators –Nested for Loops –Increment.
CSE 1301 Lecture 6B More Repetition Figures from Lewis, “C# Software Solutions”, Addison Wesley Briana B. Morrison.
Loops – While, Do, For Repetition Statements Introduction to Arrays
© 2004 Pearson Addison-Wesley. All rights reserved5-1 Iterations/ Loops The while Statement Other Repetition Statements.
An Object-Oriented Approach to Programming Logic and Design Chapter 6 Looping.
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 6: Repetition  Some additional operators increment and decrement.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 6 Repetition Statements.
SM1205 Interactivity Topic 06: Iteration and Multiple Objects Spring 2010SCM-CityU1.
CSI 101 Spring 2009 Review and Recap of Visual Basic Wednesday, April 29 th.
Chapter 5 new The Do…Loop Statement
Recursion A method is recursive if it makes a call to itself. A method is recursive if it makes a call to itself. For example: For example: public void.
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.
Chapter 4: Decision Making with Control Structures and Statements JavaScript - Introductory.
Programming Logic and Design Fifth Edition, Comprehensive
Programming Logic and Design Sixth Edition Chapter 5 Looping.
Copyright © Nancy Acemian 2004 For Loops-Break-Continue COMP For loop is a counter controlled loop. For loop is a pretest loop. Used when number.
Additional Control Structures. Chapter 9 Topics Switch Statement for Multi-way Branching Do-While Statement for Looping For Statement for Looping Using.
String Manipulation. Strings have their own properties and methods, just like a textbox or label or form does.
COMPUTER PROGRAMMING I 5.05 Apply Looping Structures.
1 Additional Control Structures. 2 Chapter 9 Topics  Switch Statement for Multi-way Branching  Do-While Statement for Looping  For Statement for Looping.
Lecture 4 Looping. Building on the foundation Now that we know a little about  cout  cin  math operators  boolean operators  making decisions using.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 24 The String Section.
CS31: Introduction to Computer Science I Discussion 1A 4/16/2010 Sungwon Yang
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 5A Repetition (Concepts)
February ,  2/16: Exam 1 Makeup Papers Available  2/20: Exam 2 Review Sheet Available in Lecture  2/27: Lab 2 due by 11:59:59pm  3/2:
CS 100 Introduction to Computing Seminar October 7, 2015.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5: Looping.
Chapter 6 Looping Structures. Do…LoopDo…Loop Statement Can operate statements repetitively Do intx=intx + 1 Loop While intx < 10 –The Loop While operates.
String Manipulation 10/21/2015 Lect#6 GC Strings have their own properties and methods, just like a textbox or label or form does. 10/21/2015 Lect#6.
CECS 5020 Computers in Education Visual Basic Variables and Constants.
ITERATION. Iteration Computers are often used to automate repetitive tasks. Repeating identical or similar tasks without making errors is something that.
Chapter Looping 5. The Increment and Decrement Operators 5.1.
REPETITION MTS3033 OBJECT ORIENTED PROGRAMMING 1.
COMP Loop Statements Yi Hong May 21, 2015.
CMSC 150 LOOPS CS 150: Fri 20 Jan Representing DNA AGTCCAGTGTCAA.
Chapter Looping 5. The Increment and Decrement Operators 5.1.
Lecture 7 – Repetition (Loop) FTMK, UTeM – Sem /2014.
COM148X1 Interactive Programming Lecture 8. Topics Today Review.
Computer C programming Chapter 3. CHAPTER 3 Program Looping –The for Statement –Nested for Loops –for Loop Variants –The while Statement –The do Statement.
Loops ( while and for ) CSE 1310 – Introduction to Computers and Programming Alexandra Stefan 1.
String and Lists Dr. José M. Reyes Álamo. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list.
Computer Programming -1-
String Manipulation Reference:
String and Lists Dr. José M. Reyes Álamo.
String Manipulation Reference:
Generating Random Numbers
Repetition Structures Chapter 9
CHAPTER 5A Loop Structure
Chapter 5: Repetition Structures
Lecture 07 More Repetition Richard Gesick.
VB Math All of your favorite mathematical operators are available in VB: + Addition - Subtraction * Multiplication / Division \ Integer Division Mod Modulo.
Additional Control Structures
String Manipulation Reference:
Chapter 6: Repetition Structures
Chapter 5: Repetition Structures
String and Lists Dr. José M. Reyes Álamo.
Faculty of Computer Science & Information System
String Manipulation Reference:
Loops.
A LESSON IN LOOPING What is a loop?
February , 2009 CSE 113 B.
Functions continued.
Introduction to Computer Science
Visual Programming COMP-315
Based on slides created by Bjarne Stroustrup & Tony Gaddis
Based on slides created by Bjarne Stroustrup & Tony Gaddis
Building Java Programs
Presentation transcript:

COM148X1 Interactive Programming Lecture 3

Topics Today String Functions Using Timer Looping

String Functions

String Class Visual Basic provides many useful string functions and they can be used through all String object Position of characters in string is starting from 0 All string functions will not alter the original string, another string variable is required to hold the result

Commonly Use String Functions FunctionDescriptionExample ToUpper() change the content to upper case s2 = s.ToUpper() ToLower() change the content to lower case s2 = s.ToLower() Length() length of string len = s.Length() Substring (pos, len) return substring from pos with length len s2 = s.Substring(2, 5) IndexOf( substring) return position of substring, return - 1 if substring not found pos = s.IndexOf(“hello”)

Commonly Use String Functions (cont’) FunctionDescriptionExample Trim() remove leading and trailing space s2 = s.Trim() Remove (pos, len) remove a number of characters from string starting from pos S2 = s.Remove(3, 5) Insert( pos, string) insert a string to pos s2 = s.Insert(3, “Hello”)

Using Timer

What is Timer Timer is an invisible stopwatchto do count down from present time Once timer finished count down, corresponding code set by programmer will be executed

Locate Timer from Toolbox

Timer Properties Enabled Count down will start if it is True Interval Number of milliseconds for count down, once finished count down, call-back function (written by programmer himself) will be executed

Looping

What is Looping Looping is a program control structure which allows computer executes part of program multiple times In Visual Basic, looping can be done by For Next loop or Do While loop

For Next Loop For Next loop mainly used to do countable repetitions, for example, calculate the total income for a year (12 months) A counter variable (a variable that is used for count) is required for the loop to count the number of repetition

For Next Loop 1 i = v1 Action i = i + 1 i  v2? yes no

For Next Loop 1 in VB For variable = v1 To v2 action Next variable Example For month = 1 to 12 income = InputBox(“Income “ & month) sum = sum + income Next month

For Next Loop 2 i = v1 Action i = i + c i  v2? yes no

For Next Loop 2 in VB For variable = v1 To v2 Step c action Next variable Example For id = 1 to max_id step 2 ‘print student name with odd id ‘… Next id

For Next Loop 3 i = v1 Action i = i + c i  v2? yes no exit before the loop complete

For Next Loop 3 in VB For variable = v1 To v2 Step c action part 1 If (condition) Then Exit For End If action part 2 Next variable Example For month = 1 to 12 income = InputBox(“Income “ & month) If (income < 0) Then MsgBox(“No more income, stop input”); Exit For End if sum = sum + income Next month

Do While Loop Unlike For Next loop, Do While loop mainly used to do uncountable repetitions, for example, supermarket calculator (different customers will buy different number of products) Do While loop can always be used to replace For Next loop but not the reverse in Visual Basic

Do While Loop 1 Action Condition yes no

Do While Loop 1 in VB Do While condition action Loop Example Do While price > 0 sum = sum + price price = InputBox(“Enter price”) Loop

Do While Loop 2 Action Condition yes no

Do While Loop 2 in VB Do action Loop While condition Example Do password = InputBox(“Password”) Loop While password <> “##21#”

Exit Do While Loop Before Completion Similar to For Next loop, Do While loop can be exit before completion by using Exit Do statement

Infinity Loop Loop that will never ends Actions that may cause infinity loop Modify counter variable during the execution of For Next loop Use wrong condition for Do While loop Forget to update variable which used in the condition of Do While loop Intentionally make it as infinity loop

Nested Loop Loop exist inside another loop The loop inside will be executed multiple times Example For row = 1 to 10 For column = 1 to 5 name = InputBox(“Student name at row = “ & row & “, col = “ & column) ‘ do something with the name ‘... next column next row