Agenda & Reading. Simple If. Decision-Making Statements. COMPSCI 280 S1C Applications Programming. Programming Fundamentals

Similar documents
News. Recap: While Loop Example. Reading. Recap: Do Loop Example. Recap: For Loop Example

CMPS 10 Introduction to Computer Science Lecture Notes

Midterms Save the Dates!

Brave New World Pseudocode Reference

Virtual Memory. Background. No. 10. Virtual Memory: concept. Logical Memory Space (review) Demand Paging(1) Virtual Memory

Assembler. Building a Modern Computer From First Principles.

9. BASIC programming: Control and Repetition

Harvard University CS 101 Fall 2005, Shimon Schocken. Assembler. Elements of Computing Systems 1 Assembler (Ch. 6)

Notes on Organizing Java Code: Packages, Visibility, and Scope

Intro. Iterators. 1. Access

11. HARMS How To: CSV Import

Pass by Reference vs. Pass by Value

Outline. Midterm Review. Declaring Variables. Main Variable Data Types. Symbolic Constants. Arithmetic Operators. Midterm Review March 24, 2014

Lecture 3: Computer Arithmetic: Multiplication and Division

Assembler. Shimon Schocken. Spring Elements of Computing Systems 1 Assembler (Ch. 6) Compiler. abstract interface.

Exercises (Part 4) Introduction to R UCLA/CCPR. John Fox, February 2005

Hierarchical clustering for gene expression data analysis

Nachos Project 3. Speaker: Sheng-Wei Cheng 2010/12/16

For instance, ; the five basic number-sets are increasingly more n A B & B A A = B (1)

6.854 Advanced Algorithms Petar Maymounkov Problem Set 11 (November 23, 2005) With: Benjamin Rossman, Oren Weimann, and Pouya Kheradpour

CHARUTAR VIDYA MANDAL S SEMCOM Vallabh Vidyanagar

Algorithm To Convert A Decimal To A Fraction

Parallelism for Nested Loops with Non-uniform and Flow Dependences

Oracle Database: SQL and PL/SQL Fundamentals Certification Course

Computer models of motion: Iterative calculations

Midterms Save the Dates!

Loop Transformations for Parallelism & Locality. Review. Scalar Expansion. Scalar Expansion: Motivation

Programming in Fortran 90 : 2017/2018

Sorting Review. Sorting. Comparison Sorting. CSE 680 Prof. Roger Crawfis. Assumptions

Loop Permutation. Loop Transformations for Parallelism & Locality. Legality of Loop Interchange. Loop Interchange (cont)

Today Using Fourier-Motzkin elimination for code generation Using Fourier-Motzkin elimination for determining schedule constraints

LLVM passes and Intro to Loop Transformation Frameworks

The Codesign Challenge

VRT012 User s guide V0.1. Address: Žirmūnų g. 27, Vilnius LT-09105, Phone: (370-5) , Fax: (370-5) ,

Active Contours/Snakes

Subspace clustering. Clustering. Fundamental to all clustering techniques is the choice of distance measure between data points;

5 The Primal-Dual Method

Compiler Design. Spring Register Allocation. Sample Exercises and Solutions. Prof. Pedro C. Diniz

NUMERICAL SOLVING OPTIMAL CONTROL PROBLEMS BY THE METHOD OF VARIATIONS

Complex Numbers. Now we also saw that if a and b were both positive then ab = a b. For a second let s forget that restriction and do the following.

TWO DIAGNOSTIC MODELS FOR PLC CONTROLLED FLEXIBLE MANUFACTURING SYSTEMS. W. HU*, A. G. STARR* and A. Y. T. LEUNG*

Loop Transformations, Dependences, and Parallelization

with Optic65 and Optic25 Cameras FOR OUTDOOR TRACKING ONLY unless used in conjunction with the Indoor Tracking Accessory.

Decision Making in C

Problem Definitions and Evaluation Criteria for Computational Expensive Optimization

High level vs Low Level. What is a Computer Program? What does gcc do for you? Program = Instructions + Data. Basic Computer Organization

5.1 The ISR: Overvieui. chapter

Polyhedral Compilation Foundations

ETAtouch RESTful Webservices

Analysis of Continuous Beams in General

y and the total sum of

Kent State University CS 4/ Design and Analysis of Algorithms. Dept. of Math & Computer Science LECT-16. Dynamic Programming

NGPM -- A NSGA-II Program in Matlab

The Greedy Method. Outline and Reading. Change Money Problem. Greedy Algorithms. Applications of the Greedy Strategy. The Greedy Method Technique

CS1100 Introduction to Programming

ANSYS FLUENT 12.1 in Workbench User s Guide

Space-Optimal, Wait-Free Real-Time Synchronization

A DATA ANALYSIS CODE FOR MCNP MESH AND STANDARD TALLIES

TN348: Openlab Module - Colocalization

Improving Low Density Parity Check Codes Over the Erasure Channel. The Nelder Mead Downhill Simplex Method. Scott Stransky

Some material adapted from Mohamed Younis, UMBC CMSC 611 Spr 2003 course slides Some material adapted from Hennessy & Patterson / 2003 Elsevier

Biostatistics 615/815

SLAM Summer School 2006 Practical 2: SLAM using Monocular Vision

Course Introduction. Algorithm 8/31/2017. COSC 320 Advanced Data Structures and Algorithms. COSC 320 Advanced Data Structures and Algorithms

Support Vector Machines

Parameter estimation for incomplete bivariate longitudinal data in clinical trials

Overview. CSC 2400: Computer Systems. Pointers in C. Pointers - Variables that hold memory addresses - Using pointers to do call-by-reference in C

Cluster Analysis of Electrical Behavior

Mathematics 256 a course in differential equations for engineering students

Outline. CIS 110: Intro to Computer Programming. What Do Our Programs Look Like? The Scanner Object. CIS 110 (11fa) - University of Pennsylvania 1

Fitting: Deformable contours April 26 th, 2018

Motivation. EE 457 Unit 4. Throughput vs. Latency. Performance Depends on View Point?! Computer System Performance. An individual user wants to:

An Entropy-Based Approach to Integrated Information Needs Assessment

Review of approximation techniques

A fault tree analysis strategy using binary decision diagrams

X- Chart Using ANOM Approach

An Optimal Algorithm for Prufer Codes *

Fault Detection in Rule-Based Software Systems

index.pdf March 20,

A New Transaction Processing Model Based on Optimistic Concurrency Control

NAG Fortran Library Chapter Introduction. G10 Smoothing in Statistics

Optimization Methods: Integer Programming Integer Linear Programming 1. Module 7 Lecture Notes 1. Integer Linear Programming

CSE 326: Data Structures Quicksort Comparison Sorting Bound

Sorting. Sorted Original. index. index

Life Tables (Times) Summary. Sample StatFolio: lifetable times.sgp

Welcome to the Three Ring %CIRCOS: An Example of Creating a Circular Graph without a Polar Axis

Avaya T3 Telephones connected to Integral 5 Setting up and using conference bridge Appendix to user s guide

Sequential search. Building Java Programs Chapter 13. Sequential search. Sequential search

Assignment # 2. Farrukh Jabeen Algorithms 510 Assignment #2 Due Date: June 15, 2009.

The example below contains two doors and no floor level obstacles. Your panel calculator should now look something like this: 2,400

Wireless Temperature Monitoring Overview

Lecture 7 Tao Wang 1

Non-Split Restrained Dominating Set of an Interval Graph Using an Algorithm

Setup and Use. Version 3.7 2/1/2014

Wishing you all a Total Quality New Year!

LECTURE NOTES Duality Theory, Sensitivity Analysis, and Parametric Programming

Innovation Typology. Collaborative Authoritativeness. Focused Web Mining. Text and Data Mining In Innovation. Generational Models

CSE 326: Data Structures Quicksort Comparison Sorting Bound

CS240: Programming in C. Lecture 12: Polymorphic Sorting

ELEC 377 Operating Systems. Week 6 Class 3

Transcription:

Agenda & Readng COMPSCI 8 SC Applcatons Programmng Programmng Fundamentals Control Flow Agenda: Decsonmakng statements: Smple If, Ifelse, nested felse, Select Case s Whle, DoWhle/Untl, For, For Each, Nested s Others Wth Usng Ext Recommended Readng: Control Flow n Vsual Basc http://msdn.mcrosoft.com/enus/lbrary/ca8tdhcs(vs.8).aspx Advanced Programmng Usng Vsual Basc.NET Appendx B: Vsual Basc Revew of Introductory of VB.NET Concepts Mcrosoft Vsual Basc 5 Step by Step Chapter 6 and 7 HandsOn Lab: Lab6 COMPSCI 8 7 6 VB DecsonMakng Statements DecsonMakng statements evaluate condtons and execute statements based on that evaluaton VB.NET ncludes two decsonmakng statements: If statement Evaluates an expresson Executes one or more statements f expresson s Can execute another statement or group of statements f expresson s Select case statement Evaluates a varable for multple values Executes a statement or group of statements, dependng on contents of the varable beng evaluated Condton True Flow chart of a typcal decson structure Condtonal COMPSCI 8 7 6 VB Code Smple If Smple If Evaluates an expresson Executes one or more statements f expresson s If condton Then If sales > 5 Then getsbonus = True commssonrate =. daysoff = daysoff + Note: You can use the snglelne form for short, smple tests. In the snglelne form. If > Then = + It s possble to have multple statements executed as the result of an If...Then decson. All statements must be on the same lne and be separated by colons. If > Then = + : = + : k = k + COMPSCI 8 7 6 VB etc.

Ifelse Ifelse Evaluates an expresson Executes one or more statements f expresson s Executes a second statement or set of statements f expresson s If condton Then If sales > 5 Then getsbonus = True getsbonus = etc. Nested felse Nested felse Ifelse or f statement can be used as a subpart of another felse or f statement. The else clause matches the most recent f clause n the same block. Note: nested statement can be very trcky to code. If ( > ) Then If ( > k) Then Console.WrteLne("A") Console.WrteLne("B") If ( > ) Then If ( > k) Then Console.WrteLne("A") Console.WrteLne("B") If sales > 5 Then getsbonus = True getsbonus = COMPSCI 8 7 6 VB 5 COMPSCI 8 7 6 VB 6 If condton Then Statement(s) If condton Then Select Case Statements(s)... Acts lke a multpleway f statement Transfers control to one of several statements, dependng on the value of an expresson testexpresson Must be an elementary data types, such as Boolean, Integer, Strng expressonlst Multple expresson clauses are separated by commas. Each clause can take one of the followng forms: expresson To expresson [ Is ] comparsonoperator expresson expresson Select case Select Case number Case To 5 Case 6, 7, 8 Case Is > 8 Case End Select Select Case testexpresson Case expressonlst statement... Case statementn End Select COMPSCI 8 7 6 VB 7 C C C True True True Statement(s) Statement(s) Statement(s) Wrtng s s Repeated executon of one or more statements untl a termnatng condton occurs Types of loops: whle Do Whle/Untl For For Each (cover n Arrays) COMPSCI 8 7 6 VB 8

Whle The Boolean expresson s checked before the loop body s executed When, the loop body s not executed at all Before the executon of each followng teraton of the loop body, the Boolean expresson s checked agan If, the loop body s executed agan If, the loop statement ends Whle condton End Whle Counters Dm counter As Integer = Whle counter < counter += End Whle Varables called counters are frequently used to control loops Counters are nvarably ntalzed before the loop begns (e.g. Dm count As Integer = ) They are also usually modfed wthn the body of the loop (e.g. count += ) The counter n the body of the loop must eventually make the test expresson Otherwse, the loop wll contnuously loop forever called an nfnte loop Dm counter As Integer = Whle counter < counter = End Whle COMPSCI 8 7 6 VB 9 COMPSCI 8 7 6 VB Do Whle The Do... constructon allows you to test a condton at ether the begnnng or the end of a loop structure. You can also specfy whether to repeat the loop whle the condton remans True or untl t becomes True. Do Whle loop executes whle the expresson s TRUE Do Untl loop executes untl the expresson s FALSE Do whle Untl condton Pretest Vs Posttest s The precedng Do Whle loops were wrtten n ther pretest syntax The expresson s always tested before the body of the loop s executed Posttest loop tests the termnatng condton at the end of the loop The nsde the body must be done once rrespectve of the expresson used Do whle Untl condton COMPSCI 8 7 6 VB COMPSCI 8 7 6 VB

For For counter ntalzaton and ncrementng code as a part of the For statement Uses pretest logc t evaluates the termnatng expresson at the begnnng of the loop Step ndcates the ncrement for count at the end of each teraton; t s optonal and defaults to f not specfed The step value can be negatve, n whch case the loop count downwards For CounterVarable = StartValue To EndValue [Step step] [CounterVarable] Incr counter Intalze the control varable Examples 'case = Do Whle ( < ) = + 'case = Do Whle ( < ) = + 'case = Do = + Whle ( < ) Case 5 'case For = To 'case 5 = Do Whle ( < ) Evaluatng the condton tmes Infnte Executng the body tmes Infnte Output COMPSCI 8 7 6 VB COMPSCI 8 7 6 VB When to use the Do Whle Use the Do Whle loop when you wsh the loop to repeat as long as the test expresson s Do Untl Use the Do Untl loop when you wsh the loop to repeat untl the test expresson s For The For loop s prmarly used when the number of requred teratons s known Posttest loops are deal when you always want the loop to terate at least once Nested s can be nested It Can be constructed usng any combnaton of Do Whle, Do Untl, or For loops When nested, the nner loop terates from begnnng to the end for each sngle teraton of the outer loop There s no lmt n Java to how many levels you can nest loops. It s usually not more than three levels. Example Multplcaton table: ROW =, COLUMN = For = To ROW For = To COLUMN product = If (product < ) Then Console.Wrte(" " & product) Console.Wrte(" " & product) 5... 5 6 8 6 9 output 6 8 6 9 COMPSCI 8 7 6 VB 5 COMPSCI 8 7 6 VB 6

Nested s Example ROW= For = To ROW For = To ROW Console.Wrte("") Outer condton <=... nner condton <= <= <= <= <= output Nested s Example ROW= For = To ROW For = To Console.Wrte("") Outer condton <= < <=... nner condton <= <= <= <= <= output COMPSCI 8 7 6 VB 7 COMPSCI 8 7 6 VB 8 Usng The usng statement establshes a statement block wthn whch you make use of a resource. You can acqure the resource wth the Usng statement. When you ext the Usng block, Vsual Basc automatcally dsposes of the resource so that t s avalable for other code to use. Usng { resourcelst resourceexpresson } statements End Usng Usng nf As New System.Drawng.Font("Aral",.F, _ System.Drawng.FontStyle.Bold) txtsrc.font = nf txtsrc.text = "Ths s pont Aral bold" End Usng Wth End Wth The wth End wth statement allows you to specfy an obect reference once and then run a seres of statements that access ts members. Ths can smplfy your code and mprove performance Wth obect End Wth Wth txtsrc.heght =.Text = "Hello, World".ForeColor = System.Drawng.Color.Green.Font = New System.Drawng.Font(.Font, System.Drawng.FontStyle.Bold) End Wth COMPSCI 8 7 6 VB 9 COMPSCI 8 7 6 VB

Ext Ext (con t) outer nner + outp ut You can use the Ext Statement to ext drectly from a control structure Ext Select Ext Whle Ext Do Ext For Snce these overrde the normal loop termnaton mechansm, they should be used sparngly For = To If ( Mod ) = Then Ext For It s used to termnate the nnermost control structure Const row As Integer = For As Integer = To row For As Integer = To row If ( + ) >= row Then Ext For Console.Wrte("") < < < < < < < = break = break COMPSCI 8 7 6 VB COMPSCI 8 7 6 VB