Repetition - Business Application Programming - Lecture Slides, Slides of Applications of Computer Sciences

Some concept of Business Application Programming are Additional Capabilities, Additional Components, Additional Class Features, Control Structures, Input and Formatting, Strings and Characters. Main points of this lecture are: Repetition, Basic Loop Structures, While Statement, Interactive While Loops, the For Statement, Do-While Statement, Recursion, Applications, Program Design, Random Numbers

Typology: Slides

2012/2013

Uploaded on 04/27/2013

mehr5
mehr5 🇮🇳

4.4

(8)

36 documents

1 / 50

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Chapter 6:
Repetition
Object-Oriented Program
Development Using Java: A
Class-Centered Approach
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32

Partial preview of the text

Download Repetition - Business Application Programming - Lecture Slides and more Slides Applications of Computer Sciences in PDF only on Docsity!

Chapter 6:

Repetition

Object-Oriented Program

Development Using Java: A

Class-Centered Approach

Objectives

  • Basic Loop Structures
  • The while Statement
  • Interactive while Loops
  • The for Statement
  • The do-while Statement
  • Recursion

Basic Loop Structures

  • Repetition statements:
    • Provide the capability to type a set of instructions once
    • Have instructions repeated continuously
    • Until some preset condition is met

Basic Loop Structures

(continued)

  • Elements required for repetition:
    • Repetition statement
    • Condition that must be evaluated
    • Statement that initially sets the condition
    • Statement within repeating section of code that allows condition to become false

Pretest and Posttest Loops

  • Pretest loop
    • The condition being tested is evaluated at the beginning of the repeating section of code - If the condition is true the executable statements within the loop are executed - If the initial value of the condition is false the executable statements within the loop are never executed at all
    • Also referred to as entrance controlled loops

Pretest and Posttest Loops

(continued)

  • Posttest loop
    • A loop that evaluates a condition at the end of a repeating section of code
    • Always executes loop statements at least once before the condition is tested
    • The do-while construct is an example of a posttest loop

Fixed-Count Versus Variable-

Condition Loops

  • Fixed-count loop
    • The condition is used to keep track of how many repetitions have occurred
    • All of Java’s repetition statements can be used
  • Variable-condition loop
    • The tested condition depends on a variable that can change interactively with each pass through the loop
    • All of Java’s repetition statements can be used

Evaluating a while Statement

  • Test condition
  • If condition has nonzero (true) value
    • Execute statement following parentheses
    • Go back to step 1
  • Else
    • Exit the while statement

Interactive while Loops

  • Combining interactive data entry with the repetition capabilities of while statements produces adaptable and powerful programs
  • A user-entered value is used in a conditional statement

Sentinels

  • Sentinels:
    • Data values that signal either the start or end of data series
    • Must be selected so as not to conflict with legitimate data values

The break and continue

Statements (continued)

  • continue statement
    • Applies only to loops created with:
      • while
      • do-while
      • for
    • When encountered in a loop the next iteration of the loop begins immediately
    • Not often used in practice

The null Statement

  • Semicolon with nothing preceding it
  • Do-nothing statement
    • Used where statement is syntactically required but no action is called for