Skip to main content Accessibility help
×
Hostname: page-component-848d4c4894-2xdlg Total loading time: 0 Render date: 2024-06-16T06:37:57.783Z Has data issue: false hasContentIssue false

Chapter 7 - Loops

Published online by Cambridge University Press:  26 August 2009

E. Reed Doke
Affiliation:
University of Arkansas
Bill C. Hardgrave
Affiliation:
University of Arkansas
Richard A. Johnson
Affiliation:
Southwest Missouri State University
Get access

Summary

OBJECTIVES

In this chapter you will study:

  • while loop;

  • do loop;

  • for loop;

  • Nested loops;

  • break statement; and

  • continue statement.

This chapter shows you how to write Java loops. You will learn how to write loops that mirror the familiar COBOL PERFORM statement including the PERFORM—UNTIL, PERFORM—VARYING—UNTIL and PERFORM—VARYING—UNTIL—AFTER. You will see that Java has three different types of loops: while, do, and for. We will use each of these to duplicate the work done by the COBOL PERFORM statement. In addition, we will review loops that test for the terminating condition at the beginning and at the end of the loop. We will also demonstrate writing nested loops in Java.

The chapter begins with the simple COBOL PERFORM—UNTIL statement and shows you how to accomplish the same thing in Java. Then we work with the PERFORM—VARYING—UNTIL and finally the PERFORM—VARYING—UNTIL—AFTER statement. Working programs are developed to illustrate the Java loop statements in action. At the end of the chapter, we design and develop a small program for the Community Naitonal Bank to compute a loan amortization, using some of the Java looping statements.

This chapter assumes you understand the following:

COBOL:

Perform-until

Inline perform (COBOL-85)

Perform-varying-until

Perform-varying-until-after

With test after (COBOL-85)

Java:

OO concepts (Chapter 2)

Java program structure (Chapter 3)

Defining data (Chapter 4)

Arithmetic (Chapter 5)

Decision making (Chapter 6)

LOOP STRUCTURE

We write program loops to repeat a sequence of instructions.

Type
Chapter
Information
Publisher: Cambridge University Press
Print publication year: 2004

Access options

Get access to the full version of this content by using one of the access options below. (Log in options will check for institutional or personal access. Content may require purchase if you do not have access.)

Save book to Kindle

To save this book to your Kindle, first ensure coreplatform@cambridge.org is added to your Approved Personal Document E-mail List under your Personal Document Settings on the Manage Your Content and Devices page of your Amazon account. Then enter the ‘name’ part of your Kindle email address below. Find out more about saving to your Kindle.

Note you can select to save to either the @free.kindle.com or @kindle.com variations. ‘@free.kindle.com’ emails are free but can only be saved to your device when it is connected to wi-fi. ‘@kindle.com’ emails can be delivered even when you are not connected to wi-fi, but note that service fees apply.

Find out more about the Kindle Personal Document Service.

  • Loops
  • E. Reed Doke, University of Arkansas, Bill C. Hardgrave, University of Arkansas, Richard A. Johnson, Southwest Missouri State University
  • Book: COBOL Programmers Swing with Java
  • Online publication: 26 August 2009
  • Chapter DOI: https://doi.org/10.1017/CBO9780511546983.009
Available formats
×

Save book to Dropbox

To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Dropbox.

  • Loops
  • E. Reed Doke, University of Arkansas, Bill C. Hardgrave, University of Arkansas, Richard A. Johnson, Southwest Missouri State University
  • Book: COBOL Programmers Swing with Java
  • Online publication: 26 August 2009
  • Chapter DOI: https://doi.org/10.1017/CBO9780511546983.009
Available formats
×

Save book to Google Drive

To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Google Drive.

  • Loops
  • E. Reed Doke, University of Arkansas, Bill C. Hardgrave, University of Arkansas, Richard A. Johnson, Southwest Missouri State University
  • Book: COBOL Programmers Swing with Java
  • Online publication: 26 August 2009
  • Chapter DOI: https://doi.org/10.1017/CBO9780511546983.009
Available formats
×