1 Sections 7.2 – 7.7 Nested Control Statements Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.

Slides:



Advertisements
Similar presentations
Chapter 4 - Control Statements
Advertisements

A8 – Control Structures if, if-else, switch Control of flow in Java Any sort of complex program must have some ability to control flow.
Session 5 JavaScript/JScript: Control Structures II Matakuliah: M0114/Web Based Programming Tahun: 2005 Versi: 5.
ISBN Chapter 3 Describing Syntax and Semantics.
LOOP / REPETITION while loop. for loop do/while loop We assume that loops are not meant to be infinite. That is, there should always be a way out of the.
Objectives In this chapter, you will learn about:
Introduction to Computers and Programming Lecture 6 Professor: Evan Korth New York University.
Slides prepared by Rose Williams, Binghamton University Chapter 3 Flow of Control Loops in Java.
 2007 Pearson Education, Inc. All rights reserved C Program Control.
Control Structures Control structures control the flow of program execution. 3 types of control structures: sequence, selection.
Describing Syntax and Semantics
Chapter 6 Control Statements Continued
ECE122 L9: While loops March 1, 2007 ECE 122 Engineering Problem Solving with Java Lecture 9 While Loops.
C How to Program, 6/e Summary © by Pearson Education, Inc. All Rights Reserved.
Fundamentals of Python: From First Programs Through Data Structures
System/Software Testing
CC0002NI – Computer Programming Computer Programming Er. Saroj Sharan Regmi Week 7.
Fundamentals of Python: First Programs
1 Chapter 7 Control Statements Continued Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Programming Logic and Design Fourth Edition, Introductory
Programming Logic and Design Sixth Edition
Chapter 3 Making Decisions
Object-Oriented Programming Using C++ Third Edition Chapter 3 Making Decisions.
Chapter 4 Introduction to Control Statements (Branching Statements) Section 1 - Additional Java Operators Section 2 - If Statements Section 3 - If-Else.
Agenda Introduction Overview of White-box testing Basis path testing
Programming Logic and Design Fifth Edition, Comprehensive
Mr. Dave Clausen1 La Cañada High School Chapter 6: Repetition Statements.
Chapter 4 Introduction to Control Statements Section 1 - Additional Java Operators Section 2 - If Statements Section 3 - If-Else Statements Section 4.
© 2006 Pearson Education 1 More Operators  To round out our knowledge of Java operators, let's examine a few more  In particular, we will examine the.
An Introduction to Programming with C++ Sixth Edition Chapter 7 The Repetition Structure.
© The McGraw-Hill Companies, 2006 Chapter 2 Selection.
Java Basics Hussein Suleman March 2007 UCT Department of Computer Science Computer Science 1015F.
 2000 Deitel & Associates, Inc. All rights reserved. Chapter 10 - JavaScript/JScript: Control Structures II Outline 10.1Introduction 10.2Essentials of.
Flow of Control Chapter 3. Outline Branching Statements Java Loop Statements Programming with Loops The Type boolean.
Chapter 6 Control Statements Continued
Chapter 4 Introduction to Control Statements
A First Book of C++ Chapter 4 Selection. Objectives In this chapter, you will learn about: –Relational Expressions –The if-else Statement –Nested if Statements.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Tevfik Bultan Lecture 4: Introduction to C: Control Flow.
4 - Conditional Control Structures CHAPTER 4. Introduction A Program is usually not limited to a linear sequence of instructions. In real life, a programme.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 2: Control Structures (Selection & Repetition)
1 Sections 6.4 – 6.5 Methods and Variables Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Debugging and Testing Hussein Suleman March 2007 UCT Department of Computer Science Computer Science 1015F.
A First Book of C++ Chapter 4 Selection.
1 Sections 3.1 – 3.2a Basic Syntax and Semantics Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
1 Sections 3.3 – 3.4 Terminal I/O and Comments Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
© 2006 Pearson Education Chapter 3 Part 2 More about Strings and Conditional Statements Loops (for and while) 1.
Control Structures I Chapter 3
Lecture 4b Repeating With Loops
Chapter 4 – C Program Control
Chapter 3: Decisions and Loops
Section 7.1 Logical Operators
Topics Introduction to Repetition Structures
CHAPTER 4 Selection CSEG1003 Introduction to Computing
Chapter 3 Loops Section 3.3 Slides prepared by Rose Williams, Binghamton University Kenrick Mock, University of Alaska Anchorage.
Loop Structures.
Topics The if Statement The if-else Statement Comparing Strings
Java Programming: Guided Learning with Early Objects
JavaScript: Control Statements.
Loops CS140: Introduction to Computing 1 Savitch Chapter 4 Flow of Control: Loops 9/18/13 9/23/13.
Topics The if Statement The if-else Statement Comparing Strings
Chapter 8: More on the Repetition Structure
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Chapter 6: Repetition Statements
Boolean Expressions to Make Comparisons
Programming Logic and Design Fifth Edition, Comprehensive
Topics Introduction to Repetition Structures
Controlling Program Flow
Control Structures.
Presentation transcript:

1 Sections 7.2 – 7.7 Nested Control Statements Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne

Chapter 3 22 Testing if Statements Quality assurance is the process of making sure software is developed to the highest standards given constraints of time and money. At minimum, test data should try to achieve complete code coverage. – When all lines of code are tested at least once. – Not the same as testing all logical paths. 2

Chapter 3 33 Testing if Statements (continued) Equivalence class: all the sets of test data that exercise a program in the same manner. Boundary conditions: test data that assesses a program’s behavior on or near the boundaries between equivalence classes. Extreme conditions: data at the limits of validity. Must also test data validation rules. – Enter values that are valid and invalid, and test the boundary values between the two. 3

Chapter 3 44 Nested if Statements Nested if statements are an alternative to using logical operators in a complex program. 4 An everyday example of nested ifs written in Javish

Chapter 3 55 Nested if Statements (continued) 5 Flowchart for reading a book, watching TV, or going for a walk

Chapter 3 66 Logical Errors in Nested if Statements Removing the Braces: Better to overuse braces than underuse. Braces and indentation can also help readability. Avoiding Nested if statements: Sometimes helps to avoid logical errors. Rewrite as a series of independent if statements. 6

Chapter 3 77 Nested Loops A nested loop is a loop inside another loop. Example: determining if a number is prime. – Nesting a for loop inside another for loop. – Compute all the primes between two limits. – To enter another pair of limits, enclose the code in yet another loop. 7

Chapter 3 88 Testing Loops Looping statements make it challenging to design good test data. Frequently, loops iterate zero, one, or more than one time depending on a program’s inputs. Combinatorial Explosion: When the behavior of different program parts affects other parts, include all options in testing. Multiplicative growth: number of parts * number of test data sets. 8

Chapter 3 99 Testing Loops (continued) 9 Robust Programs: A program that produces correct results when it has valid inputs is not good enough. Must test using invalid data. A program that tolerates and recovers from errors in input is robust.

Chapter 3 10 Loop Verification The process of guaranteeing that a loop performs its intended task, independent of testing. The assert Statement: Allows the programmer to evaluate a Boolean expression and halt the program with an error message if the expression’s value is false. If true, the program continues. 10

Chapter 3 11 Loop Verification (continued) 11 Assertions with Loops: Input assertions: state what should be true before a loop is entered. Output assertions: state what should be true when the loop is exited.

Chapter 3 12 Loop Verification (continued) 12 Invariant and Variant Assertions: Loop invariant: an assertion that exposes a relationship between variables that remains constant throughout all loop iterations. – True before the loop is entered, and after each pass. Loop variant: an assertion whose truth changes between the first and final execution of the loop. – Guarantees the loop is exited.

Chapter 3 13 Summary 13 Nested if statements are another way of expressing complex conditions. A nested if statement can be translated to an equivalent if statement that uses logical operators. An extended or multiway if statement expresses a choice among several mutually exclusive alternatives.

Chapter 3 14 Summary (continued) 14 Loops can be nested in other loops. Equivalence classes, boundary conditions, and extreme conditions are important features used in tests of control structures involving complex conditions. You can verify the correctness of a loop by using assertions, loop variants, and loop invariants.

Chapter 3 15