4.2 The while Loop

Ace your homework & exams now with Quizwiz!

How many times will "Hello World" be printed in the following code segment? int count = 10; while (count < 1) { System.out.println("Hello World"); count++; }

0 times

Iteration

Each repetition of a loop

loop header

The first the line shown in the format of a loop

In most cases, loops must contain within themselves a way to terminate.

True

The programming style you should use with the while loop is similar to that of the if statement.

True

infinite loop

a loop that does not have a way of stopping

loop control variable

a variable whose value determines whether loop execution continues

If a loop does not have a way of stopping, it is called a(n) _____.

infinite loop

What are the 3 loop control structures in Java?

the while loop, the do-while loop, and the for loop.

the body of the loop

The statement that is repeated if the condition is true.

True or False: An important characteristic of the while loop is that the loop will never iterate if the boolean expression is false to start with.

True

True or False: The while loop has two important parts: (1) a boolean expression that is tested for a true or false value, and (2) a statement or block that is repeated as long as the expression is true.

True

The while loop

has two important parts: (1) a boolean expression that is tested for a true or false value (2) a statement or block of statements that is repeated as long as the expression is true.

How many times will "I love Java programming!" be printed in the following code segment? int count = 0; while (count < 10) System.out.println("I love Java programming!);

infinitely

When the following code executes, how many times will Programming is awesome! be displayed? int number = 3; while (number > 0) System.out.println("Programming is awesome!"); number--;

infinitely

A loop

is a control structure that causes a statement or group of statements to repeat.

while loop

is known as a pretest loop, which means it tests its expression before each iteration.

Each repetition of a loop is commonly referred to as a(n) _____.

iteration

Given an int variable k that has already been declared , use a while loop to print a single line consisting of 88 asterisks. Use no variables other than k.

k = 1; while (k <= 88) { System.out.print('*'); k++; } System.out.println();

The while loop is known as a _____ loop, which means it tests its expression before each iteration.

pretest

Given an int variable n that has already been declared and initialized to a positive value , use a while loop to print a single line consisting of n asterisks. Use no variables other than n.

while (n > 0) { System.out.print('*'); n--; } System.out.println();


Related study sets

Government Chapter 4 Reading Quiz

View Set

Classes of life Insurance Policies

View Set

3.5 Special Cases: Repeated and Zero Eigenvalues

View Set

LearningCurve: 15b. The Biomedical Therapies and Preventing Psychological Disorders

View Set

IBM Week 10/ 11/ 13 - Human Resources Management (HRM)

View Set