Haidong Xue Summer 2011, at GSU

Slides:



Advertisements
Similar presentations
Java Control Statements
Advertisements

Control Structures.
Module 4: Statements and Exceptions. Overview Introduction to Statements Using Selection Statements Using Iteration Statements Using Jump Statements Handling.
Making Choices in C if/else statement logical operators break and continue statements switch statement the conditional operator.
1 Conditional Statement. 2 Conditional Statements Allow different sets of instructions to be executed depending on truth or falsity of a logical condition.
Written by: Dr. JJ Shepherd
Switch Switch case statements are a substitute for long if statements that compare a variable to several "integral" values ("integral" values are simply.
Principles of Computer Programming (using Java) Haidong Xue Summer 2011, at GSU Copyright © 2000 W. W. Norton & Company. All rights reserved. 1.
The switch StatementtMyn1 The switch Statement Sometimes there can be a multiple-choice situation, in which you need to execute a particular set of statements.
Principles of Computer Programming (using Java) Review Haidong Xue Summer 2011, at GSU.
Assertions Program correctness. Assertions Java statement – enables you to assert an assumption about your program. – An assertion contains a Boolean.
Basic Java Programming CSCI 392 Week Two. Stuff that is the same as C++ for loops and while loops for (int i=0; i
1 CSC103: Introduction to Computer and Programming Lecture No 11.
Selection (if-then-else) Programming Has 3 Types of Control: Sequential (normal): Control of Execution Proceeds One after the Other Selection (if-then-else):
Spring 2008 Mark Fontenot CSE 1341 Principles of Computer Science I Note Set 10.
Additional Control Structures. Chapter 9 Topics Switch Statement for Multi-way Branching Do-While Statement for Looping For Statement for Looping Using.
CSc2310 tutoring session, week 8 Fall, 2012 Haidong Xue 5:30pm—8:30pm 11/06/2012 and 11/07/2012 -Test 3 Study Guide.
1 Chapter 9 Additional Control Structures Dale/Weems.
1 Do-While Statement Is a looping control structure in which the loop condition is tested after each iteration of the loop. SYNTAX do { Statement } while.
Chapter 05 (Part III) Control Statements: Part II.
The switch Statement.  Occasionally, an algorithm will contain a series of decisions in which a variable or expression is tested separately for each.
Exceptions in C++. Exceptions  Exceptions provide a way to handle the errors generated by our programs by transferring control to functions called handlers.
Exceptions and Assertions Chapter 15 – CSCI 1302.
1 Programming in C++ Dale/Weems/Headington Chapter 9 Additional Control Structures (Switch, Do..While, For statements)
Written by: Dr. JJ Shepherd
Chapter 1 Java Programming Review. Introduction Java is platform-independent, meaning that you can write a program once and run it anywhere. Java programs.
1 Handling Errors and Exceptions Chapter 6. 2 Objectives You will be able to: 1. Use the try, catch, and finally statements to handle exceptions. 2. Raise.
C syntax (simplified) BNF. Program ::= [ ] Directives ::= [ ] ::= | |… ::=#include > ::=#define.
Chapter 7 Control Structures. Java has very flexible three looping mechanisms. You can use one of the following three loops:  while Loop  do...while.
Review for Test2. Scope 8 problems, 60 points. 1 Bonus problem (5 points) Coverage: – Test 1 coverage – Exception Handling, Switch Statement – Array of.
PHP Condtions and Loops Prepared by Dr. Maher Abuhamdeh.
C++ Lesson 1.
Information and Computer Sciences University of Hawaii, Manoa
Java Exceptions a quick review….
Week 3 - Friday CS222.
Haidong Xue Summer 2011, at GSU
C++, OBJECT ORIENTED PROGRAMMING
More Control Structures
Haidong Xue Summer 2011, at GSU
2.0 FUNDAMENTALS OF JAVA PROGRAMMING LANGUAGE
11/10/2018.
Yong Choi School of Business CSU, Bakersfield
Advanced Java Programming
Principles of Computer Programming (using Java) Chapter 2, Part 1
ATS Application Programming: Java Programming
Final Review Dr. Xiaolin Hu.
CHAPTER 5 (PART 2) JAVA FILE INPUT/OUTPUT
محاضرة 1: مقدمة للمسـاق و مراجعـة للأساسيـات
Exception Handling and Reading / Writing Files
Exception Handling Chapter 9 Edited by JJ.
Exception Handling.
Exception Handling in Java
Arrays, Part 1 of 2 Topics Definition of a Data Structure
Chap 1 Chap 2 Chap 3 Chap 5 Surprise Me
Programming in C# CHAPTER - 7
Homework Any Questions?.
Review for Test2.
Final Review Fan Bai Csc 2310 Spring 2012.
The Java switch Statement
Object-Oriented Programming (OOP) Lecture No. 43
Fundamental Programming
Introduction to Programming
The switch Statement When we want to compare a variable against several values to see which one it has, we can use the switch statement: switch (status)
Final Review Dr. Xiaolin Hu.
Haidong Xue Summer 2011, at GSU
Haidong Xue Summer 2011, at GSU
Controlling Program Flow
Principles of Computer Programming (using Java) Chapter 5 Arrays
C++ Programming Lecture 7 Control Structure I (Selection) – Part II
Switch Case Structures
Presentation transcript:

Haidong Xue Summer 2011, at GSU Principles of Computer Programming (using Java) Chapter 8 More Control Structures Haidong Xue Summer 2011, at GSU

Content Quiz4 Assignment5 break and continue in if structure and loops switch structure exceptions

Quiz4 1:50pm – 2:00pm

Assignment5 Answers Should we output the result in DatabaseLogic.java? Why?

break and continue Always exit or go back to the nearest structure Example: BreakContinue.java

Labeled break and continue Exit or go back to the structure with the label Example: LabeledBreakContinue

switch structure switch ( expression ) { Integer (int, long ,short), char or enumeration expression switch ( expression ) { case constant-expression : statements … default : statements } The value can be determined by the compiler

switch structure What are the statements that are executed? The location of default Example: TestSwitch.java

Exceptions Type of exceptions: Throw a exception Checked exceptions (thrown by throw statements) Unchecked exceptions (embedded exceptions) Throw a exception throw exception_object;

Exceptions Handling exceptions Examples: TestExceptions.java try block catch (exception-type identifier) Examples: TestExceptions.java Improve previous codes

Assignment 6 Improve assignment 4, to solve the problem when the denominator is 0 Improve assignment 5, to solve the exceptions incurred by illegal inputs

Test 2 and Test 3 Test 2: Test 3: Using classes Structures: if, while, do-while, for, switch Using arrays Using methods (how parameters are passed) Exceptions Test 3: Everything

Grading policy [50, 100] <=> B-, B, B+, A-, A [0, 50] <=> F to C