Loops in Java - PowerPoint PPT Presentation

1 / 9
About This Presentation
Title:

Loops in Java

Description:

Loops in Java. For loop. Do loop. While loop. 15-100. 2. Boolean ... Update the appropriate variables. infinite loop. What is that needs to be repeated? ... – PowerPoint PPT presentation

Number of Views:44
Avg rating:3.0/5.0
Slides: 10
Provided by: qata
Category:
Tags: java | loops | update

less

Transcript and Presenter's Notes

Title: Loops in Java


1
Loops in Java
  • For loop
  • Do loop
  • While loop

2
Boolean Operators
  • Comparison Operators
  • lt
  • lt
  • gt
  • gt
  • !
  • Binary Operators
  • and
  • or
  • not !

3
Simple Control Structures
  • To alter sequential execution we need control
    structures
  • means to test and evaluate
  • conditionals
  • means to repeat and iterate
  • loops

4
Need for Iteration
  • Loops are needed to avoid repetitive code
  • Conditionals execute only once!

5
While loop
  • boolean test for entry (loop guard)
  • body of the loop
  • may not execute at all
  • x 5
  • while(x lt 100 x gt 0)
  • g.drawOval(x,y,15,15)
  • x x 50

6
For Loop
  • initialization
  • loop guard
  • update
  • body of the loop
  • may not execute at all
  • for(x 5 x gt 0 x lt 100 x x 50)
  • g.drawOval(x,y,15,15)

7
Do loop
  • boolean test for exit
  • body of the loop
  • always executes at least once
  • x 5
  • do
  • g.drawOval(x,y,15,15)
  • x x 50
  • while(x lt 100 x gt 0)

8
Designing a Loop
  • When do we stop?
  • Reverse (or negate) the stopping condition
  • loop guard
  • What is the initial state?
  • Update the appropriate variables
  • infinite loop
  • What is that needs to be repeated?
  • body of the loop

9
Homework
  • Read the following
  • Chapter 8 (BP)
  • Lab 04 is due this coming Sunday the 25th
  • Go over Exercise_7.doc
  • Exam I is on Thursday the 29th
  • Open book open notes
  • 2 problems similar to labs 3 4
  • 70 minutes
Write a Comment
User Comments (0)
About PowerShow.com