ch06 - Java Programming Fourth Edition Chapter 6 Looping...

Info iconThis preview shows pages 1–12. Sign up to view the full content.

View Full Document Right Arrow Icon
Java Programming Fourth Edition Chapter 6 Looping
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Java Programming, Fourth Edition 2 Objectives • Learn about the loop structure • Use a while loop • Use shortcut arithmetic operators • Use a for loop • Learn how and when to use a do. ..while loop • Learn about nested loops • Understand how to improve loop performance
Background image of page 2
Java Programming, Fourth Edition 3 Learning About the Loop Structure • Loop – Structure allows repeated execution of a block of statements • Loop body – Block of statements – Executed repeatedly
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Java Programming, Fourth Edition 4 Learning About the Loop Structure (continued) • Three types of loops – while – for – do. ..while
Background image of page 4
Java Programming, Fourth Edition 5 Flowchart of a Loop Structure
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Java Programming, Fourth Edition 6 Using a while Loop To Create a Definite Loop • while loop – Executes body of statements continually – As long as Boolean expression that controls entry into loop continues to be true • Consists of keyword while – Followed by Boolean expression within parentheses – Followed by body of loop • Can be single statement or block of statements surrounded by curly braces
Background image of page 6
Java Programming, Fourth Edition 7 A while Loop that Prints the Integers 1 through 10
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Java Programming, Fourth Edition 8 Using a while Loop To Create a Definite Loop (continued) • Definite loop – Performs task predetermined number of times – Also called counted loop • Write a definite loop – Initialize loop control variable • Variable whose value determines whether loop execution continues – While loop control variable does not pass limiting value • Program continues to execute body of while loop
Background image of page 8
Java Programming, Fourth Edition 9 Using a while Loop To Create a Definite Loop (continued) • Write a definite loop (continued) – Body of loop • Must include statement that alters loop control variable • Infinite loop – Loop that never ends – Can result from mistake in while loop – Don’t intentionally write
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Java Programming, Fourth Edition 10 A Loop that Displays “Hello” Infinitely
Background image of page 10
Java Programming, Fourth Edition 11 Using a while Loop To Create a Definite Loop (continued) • Suspect infinite loop – Same output displayed repeatedly – Screen remains idle for extended period of time • Exit from infinite loop – Press and hold Ctrl • Press C or Break
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 12
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 38

ch06 - Java Programming Fourth Edition Chapter 6 Looping...

This preview shows document pages 1 - 12. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online