Debugging October 4, 2006 ComS 207: Programming I (in Java)

Slides:



Advertisements
Similar presentations
CS 101 Introductory Programming - Lecture 7: Loops In C & Good Coding Practices Presenter: Ankur Chattopadhyay.
Advertisements

Loops –Do while Do While Reading for this Lecture, L&L, 5.7.
Copyright © 2012 Pearson Education, Inc. Chapter 6 More Conditionals and Loops Java Software Solutions Foundations of Program Design Seventh Edition John.
Loops – While, Do, For Repetition Statements Introduction to Arrays
Chapter Day 14. © 2007 Pearson Addison-Wesley. All rights reserved5-2 Agenda Day 14 Problem set 3 posted  10 problems from chapters 5 & 6  Due in 11.
Loops –For For Reading for this Lecture, L&L, Part of 5.8.
ECE122 L11: For loops and Arrays March 8, 2007 ECE 122 Engineering Problem Solving with Java Lecture 11 For Loops and Arrays.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Loops Repetition Statements. Repetition statements allow us to execute a statement multiple times Often they are referred to as loops Like conditional.
© 2004 Pearson Addison-Wesley. All rights reserved5-1 Iterations/ Loops The while Statement Other Repetition Statements.
Copyright © Texas Education Agency, Computer Programming For Loops.
Chapter Day 12. © 2007 Pearson Addison-Wesley. All rights reserved5-2 Agenda Day 12 Problem set corrected  1 A, 2 B’s and 1 D Starting Late and not turning.
ECE122 L9: While loops March 1, 2007 ECE 122 Engineering Problem Solving with Java Lecture 9 While Loops.
Chapter 5 Conditionals and Loops. © 2004 Pearson Addison-Wesley. All rights reserved5-2 Conditionals and Loops Now we will examine programming statements.
© 2004 Pearson Addison-Wesley. All rights reserved February 17, 2006 The ‘while’ Statement ComS 207: Programming I (in Java) Iowa State University, SPRING.
© 2004 Pearson Addison-Wesley. All rights reserved February 20, 2006 ‘do’ and ‘for’ loops ComS 207: Programming I (in Java) Iowa State University, SPRING.
Chapter 5 Loops.
© 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.
Copyright © 2012 Pearson Education, Inc. Chapter 6 More Conditionals and Loops Java Software Solutions Foundations of Program Design Seventh Edition John.
Chapter 5 – Part 3 Conditionals and Loops. © 2004 Pearson Addison-Wesley. All rights reserved5-2 Outline The if Statement and Conditions Other Conditional.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
Topics Logical Operators (Chapter 5) Comparing Data (Chapter 5) The conditional operator The switch Statement The for loop Nested Loops.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
1 Program Development  The creation of software involves four basic activities: establishing the requirements creating a design implementing the code.
1 b Boolean expressions b truth tables b conditional operator b switch statement b repetition statements: whilewhile do/whiledo/while forfor Lecture 3.
CMSC 150 LOOPS CS 150: Fri 20 Jan Representing DNA AGTCCAGTGTCAA.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
CSE 501N Fall ’09 07: Iteration 17 September 2009 Nick Leidenfrost.
Repetition Statements b Repetition statements allow us to execute a statement multiple times repetitively b They are often simply referred to as loops.
Flow of Control (2) : Loops Clark Savage Turner, J.D., Ph.D. Some lecture slides have been adapted from those developed.
Programming in Java (COP 2250) Lecture 12 & 13 Chengyong Yang Fall, 2005.
Chapter 5 – Part 3 Conditionals and Loops. © 2004 Pearson Addison-Wesley. All rights reserved2/19 Outline The if Statement and Conditions Other Conditional.
Conditional Statements A conditional statement lets us choose which statement will be executed next Conditional statements give us the power to make basic.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
© 2004 Pearson Addison-Wesley. All rights reserved October 5, 2007 Arrays ComS 207: Programming I (in Java) Iowa State University, FALL 2007 Instructor:
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
if ( condition ) statement; if is a Java reserved word The condition must be a boolean expression. It must evaluate to either true or false.
© 2006 Pearson Education Chapter 3 Part 2 More about Strings and Conditional Statements Loops (for and while) 1.
Topic : While, For, Do-While Loop Guided By : Branch : Batch :
CprE 185: Intro to Problem Solving (using C)
Chapter 4 Repetition Statements (loops)
Chapter 6 More Conditionals and Loops
Data Conversion & Scanner Class
Loop Structures.
Boolean Expressions & the ‘if’ Statement
The switch Statement The switch statement provides another way to decide which statement to execute next The switch statement evaluates an expression,
Chapter 6 More Conditionals and Loops
Debugging October 3, 2007 ComS 207: Programming I (in Java)
Outline Altering flow of control Boolean expressions
2D Arrays October 12, 2007 ComS 207: Programming I (in Java)
The ‘while’ Statement September 27, 2006
Chapter 3: Program Statements
Recursion (part 1) October 24, 2007 ComS 207: Programming I (in Java)
3.5- The while Statement The while statement has the following syntax:
What output is produced by the following fragment?
CprE 185: Intro to Problem Solving (using C)
Arrays October 6, 2006 ComS 207: Programming I (in Java)
Midterm Review October 23, 2006 ComS 207: Programming I (in Java)
PROGRAM FLOWCHART Iteration Statements.
Comparing Data & the ‘switch’ Statement
Comparing Data & the ‘switch’ Statement
CprE 185: Intro to Problem Solving (using C)
Chap 7. Advanced Control Statements in Java
CSCI 1100/1202 February 6, 2002.
‘do’ and ‘for’ loops October 1, 2007 ComS 207: Programming I (in Java)
Recursion (part 1) October 25, 2006 ComS 207: Programming I (in Java)
CprE 185: Intro to Problem Solving (using C)
‘do’ and ‘for’ loops October 2, 2006 ComS 207: Programming I (in Java)
Presentation transcript:

Debugging October 4, 2006 ComS 207: Programming I (in Java) Iowa State University, FALL 2006 Instructor: Alexander Stoytchev © 2004 Pearson Addison-Wesley. All rights reserved

HW Questions? © 2004 Pearson Addison-Wesley. All rights reserved

Quick review of last lecture © 2004 Pearson Addison-Wesley. All rights reserved

Logic of a do Loop statement true condition evaluated false © 2004 Pearson Addison-Wesley. All rights reserved

The do Statement A do statement has the following syntax: do { } while ( condition ) The statement is executed once initially, and then the condition is evaluated The statement is executed repeatedly until the condition becomes false © 2004 Pearson Addison-Wesley. All rights reserved

Comparing while and do The while Loop The do Loop statement condition true false condition evaluated The while Loop true condition evaluated statement false The do Loop © 2004 Pearson Addison-Wesley. All rights reserved

The do Statement An example of a do loop: int count = 0; do { count++; System.out.println (count); } while (count < 5); The body of a do loop executes at least once See ReverseNumber.java (page 244) © 2004 Pearson Addison-Wesley. All rights reserved

The for Statement A for statement has the following syntax: The initialization is executed once before the loop begins The statement is executed until the condition becomes false for ( initialization ; condition ; increment ) statement; The increment portion is executed at the end of each iteration © 2004 Pearson Addison-Wesley. All rights reserved

Logic of a for loop initialization condition evaluated false statement true increment © 2004 Pearson Addison-Wesley. All rights reserved

The for Statement A for loop is functionally equivalent to the following while loop structure: initialization; while ( condition ) { statement; increment; } © 2004 Pearson Addison-Wesley. All rights reserved

The for Statement An example of a for loop: for (int count=1; count <= 5; count++) System.out.println (count); The initialization section can be used to declare a variable Like a while loop, the condition of a for loop is tested prior to executing the loop body Therefore, the body of a for loop will execute zero or more times © 2004 Pearson Addison-Wesley. All rights reserved

The for Statement The increment section can perform any calculation for (int num=100; num > 0; num -= 5) System.out.println (num); A for loop is well suited for executing statements a specific number of times that can be calculated or determined in advance See Multiples.java (page 248) See Stars.java (page 250) © 2004 Pearson Addison-Wesley. All rights reserved

Example: Multiples.java (page 248) © 2004 Pearson Addison-Wesley. All rights reserved

Example: Stars.java (page 250) © 2004 Pearson Addison-Wesley. All rights reserved

The for Statement Each expression in the header of a for loop is optional If the initialization is left out, no initialization is performed If the condition is left out, it is always considered to be true, and therefore creates an infinite loop If the increment is left out, no increment operation is performed © 2004 Pearson Addison-Wesley. All rights reserved

Note: This material is not from the textbook Note: This material is not from the textbook. It is from the jGRASP manual. © 2004 Pearson Addison-Wesley. All rights reserved

How to use the jGRASP Debugger © 2004 Pearson Addison-Wesley. All rights reserved

© 2004 Pearson Addison-Wesley. All rights reserved

© 2004 Pearson Addison-Wesley. All rights reserved

© 2004 Pearson Addison-Wesley. All rights reserved

© 2004 Pearson Addison-Wesley. All rights reserved

© 2004 Pearson Addison-Wesley. All rights reserved

© 2004 Pearson Addison-Wesley. All rights reserved

© 2004 Pearson Addison-Wesley. All rights reserved

Debugging Examples and Demos © 2004 Pearson Addison-Wesley. All rights reserved

Example: Multiples.java (page 248) © 2004 Pearson Addison-Wesley. All rights reserved

Example: Stars.java (page 250) © 2004 Pearson Addison-Wesley. All rights reserved

Other Things About Loops ‘Break’ Statement ‘Continue’ Statement Empty Statement - ‘;’ © 2004 Pearson Addison-Wesley. All rights reserved

The for Statement A for statement has the following syntax: The initialization is executed once before the loop begins The statement is executed until the condition becomes false for ( initialization ; condition ; increment ) statement; The increment portion is executed at the end of each iteration © 2004 Pearson Addison-Wesley. All rights reserved

The for Statement Each expression in the header of a for loop is optional If the initialization is left out, no initialization is performed If the condition is left out, it is always considered to be true, and therefore creates an infinite loop If the increment is left out, no increment operation is performed © 2004 Pearson Addison-Wesley. All rights reserved

THE END © 2004 Pearson Addison-Wesley. All rights reserved