Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
11th Edition
ISBN: 9780134743356
Author: Paul J. Deitel, Harvey Deitel
Publisher: PEARSON
bartleby

Concept explainers

bartleby

Videos

Textbook Question
Book Icon
Chapter 5, Problem 1.1SRE

Fill in the blanks in each of the following statements:

Typically,    statements are used for counter-controlled

iteration and    statements for sentinel-controlled iteration.

Expert Solution & Answer
Check Mark
Program Description Answer

The “for loop” statements are used for counter-controlled iteration and “while loop” statements used for sentinel-controlled iteration.

Explanation of Solution

“for” loop:

  • The for loop gets starts with the keyword “for”. It contains three control structures and these control structures are separated using (;) semicolon. They are:
    • “Initial-action”, used to initialize the control variable.
    • “Loop-continuation-condition”, it determines whether the loop gets repeated.
    • “Action-after-each-iteration”, used to update the control variable for next iteration.
    • So, the “for” loop always used for counter-controlled iteration.

A for loop is used to execute a block of statements repeatedly until the condition is true. The syntax of for loop:

for(i=initial_value;i<end_value;i++)

{

  Loop statements;

}

  • Here, the variable “i” is referred as control variable, it controls how many times that the loop gets executed.

“while” loop:

The “while” loop first checks its expression and then the statements inside the loop are executed. It is also called as pretest loops.

  • These loops do not have to be terminated with a semicolon.
  • With the false expressions, the loops can be terminated.
  • So, the “while” loop always used for sentinel-controlled iteration.

Syntax:

The syntax for the while loop is as follows:

//while loop statement

while (condition)

{

    //statement

}

Want to see more full solutions like this?

Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Students have asked these similar questions
What is the output from each of the following pseudocode statements?
5. (Algebra: solve 2 X 2 linear equations) You can use Cramer's rule to solve the following 2 X 2 system of linear equation: ax + by = e cx + dy = f ● x = ed - bf bc ad y = af - ec ad bc - Write a program that prompts the user to enter a, b, c, d, e, and f and display the result. If ad- bc is 0, report that The equation has no solution. Enter a, b, c, d, e, f: 9.0, 4.0, 3.0, -5.0, -6.0, -21.0 Enter x is -2.0 and y is 3.0 Enter a, b, c, d, e, f: 1.0, 2.0, 2.0, 4.0, 4.0, 5.0 Enter The equation has no solution
(DEBUG AND MAKE A FLOWCHART OF THIS PROGRAM) // This pseudocode is intended to display// employee net pay values. All employees have a standard// $45 deduction from their checks.// If an employee does not earn enough to cover the deduction,// an error message is displayed.// This example is modularized.start   Declarations      string name      string EOFNAME = ZZZZ   while name not equal to EOFNAME      housekeeping()   endwhile   while name not equal to EOFNAME      mainLoop()   endwhile   while name not equal to EOFNAME      finish()   endwhilestop housekeeping()   output "Enter first name or ", EOFNAME, " to quit "return mainLoop()   Declarations      num hours      num rate      num DEDUCTION = 45      num net   output "Enter hours worked for ", name   input hours   output "Enter hourly rate for ", name   input rate   gross = hours * rate   net = gross - DEDUCTION   if net > 0 then      output "Net pay for ", name, " is ", net   else      output "Deductions not covered. Net is…

Chapter 5 Solutions

Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)

Ch. 5 - State whether each of the following is true or...Ch. 5 - Prob. 2.5SRECh. 5 - State whether each of the following is true or...Ch. 5 - Prob. 2.7SRECh. 5 - Prob. 3.1SRECh. 5 - Prob. 3.2SRECh. 5 - Write a Java statement or a set of Java statements...Ch. 5 - Prob. 3.4SRECh. 5 - Find the error in each of the following code...Ch. 5 - Find the error in each of the following code...Ch. 5 - Find the error in each of the following code...Ch. 5 - Find the error in each of the following code...Ch. 5 - Describe the four basic elements of...Ch. 5 - Compare and contrast the while and for iteration...Ch. 5 - Prob. 3.1ECh. 5 - Compare and contrast the break and continue...Ch. 5 - Find and correct the error(s) in each of the...Ch. 5 - The following code should print whether integer...Ch. 5 - Prob. 5.3ECh. 5 - Find and correct the error(s) in each of the...Ch. 5 - What does the following program do? 1 // Exercise...Ch. 5 - (Find the Smallest Value) Write an application...Ch. 5 - (Calculating the Product of Odd Integers) Write an...Ch. 5 - (Factorials) Factorials are used frequently in...Ch. 5 - (Modified Compound-Interest Program) Modify the...Ch. 5 - (Triangle Printing Program) Write an application...Ch. 5 - (Bar-Chart Printing Program) One interesting...Ch. 5 - (Calculating Sales) An online retailer sells five...Ch. 5 - (Modified Compound-Interest Program) Modify the...Ch. 5 - Assume that i = 1, j = 2, k = 3 and m = 2. What...Ch. 5 - (Calculating the Value of ) Calculate the value of...Ch. 5 - (Pythagorean Triples) A right triangle can have...Ch. 5 - (Modified Triangle-Printing Program) Modify...Ch. 5 - (De Morgans Laws) In this chapter, we discussed...Ch. 5 - (Diamond-Printing Program) Write an application...Ch. 5 - Prob. 21.1ECh. 5 - A criticism of the break statement and the...Ch. 5 - What does the following program segment do? 1 for...Ch. 5 - Describe in general how youd remove any continue...Ch. 5 - Prob. 25.1E
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Literals in Java Programming; Author: Sudhakar Atchala;https://www.youtube.com/watch?v=PuEU4S4B7JQ;License: Standard YouTube License, CC-BY
Type of literals in Python | Python Tutorial -6; Author: Lovejot Bhardwaj;https://www.youtube.com/watch?v=bwer3E9hj8Q;License: Standard Youtube License