Exam 6: Looping

arrow
  • Select Tags
search iconSearch Question
flashcardsStudy Flashcards
  • Select Tags

Use a(n) ____ loop to execute a body of statements continually as long as the Boolean expression that controls entry into the loop continues to be true .

Free
(Multiple Choice)
4.9/5
(35)
Correct Answer:
Verified

B

How are indefinite loops used for validating data? Why is a loop structure typically the better choice for validating data than an if statement?

Free
(Essay)
4.9/5
(45)
Correct Answer:
Verified

Programmers commonly use indefinite loops when validating input data. Validating data is  the process of ensuring that a value falls within a specified range. For example, suppose you  require a user to enter a value no greater than 3. If the user enters 3 or less at the first prompt, the loop never executes. However, if the user enters a number greater than 3, the shaded loop executes, providing the user with another chance to enter a correct value. While the user continues to enter incorrect data, the loop repeats. Novice programmers often make the mistake of checking for invalid data using a decision instead of a loop. That is, they ask whether the data is invalid using an if statement; if the data is invalid, they reprompt the user. However, they forget that a user might enter incorrect data multiple times. Usually, a loop is the best structure to use when validating input data.

Match each term with the correct statement below.
Premises:
Multiple statements within curly braces
Responses:
*=
block
accumulating
Correct Answer:
Verified
Premises:
Responses:
Multiple statements within curly braces
*=
Free
(Matching)
4.8/5
(32)
Correct Answer:
Verified

When creating a for loop, which statement will correctly initialize more than one variable?

(Multiple Choice)
4.7/5
(38)

You can use virtually any number of nested loops; however, at some point, your machine will no longer be able to store all the necessary looping information.

(True/False)
4.8/5
(47)

In the expressions b = 8 and c = --b , what value will be assigned to the variable c ?

(Multiple Choice)
4.9/5
(39)

When nesting loops, the variable in the outer loop changes more frequently.

(True/False)
5.0/5
(34)

You can initialize one or more variables in the first section of a  for  statement.

(True/False)
4.8/5
(35)

Making a comparison to 0 is slower than making a comparison to any other value.

(True/False)
4.8/5
(37)
Match each term with the correct statement below.
Premises:
A shortcut for incrementing and accumulating
Responses:
data validation
decrementing
loop control variable
Correct Answer:
Verified
Premises:
Responses:
A shortcut for incrementing and accumulating
data validation
(Matching)
4.7/5
(35)

The ____ loop is the posttest loop used in Java.

(Multiple Choice)
4.7/5
(43)

Which is an infinite loop?

(Multiple Choice)
4.9/5
(34)

The statements that make up a loop body will continue to execute as long as the expression value remains false.

(True/False)
4.9/5
(44)
Match each term with the correct statement below.
Premises:
The technique of combining two loops into one
Responses:
for loop
prefix ++
loop fusion
Correct Answer:
Verified
Premises:
Responses:
The technique of combining two loops into one
for loop
(Matching)
4.8/5
(32)
Match each term with the correct statement below.
Premises:
Performs no actions in its body
Responses:
for loop
decrementing
empty body
Correct Answer:
Verified
Premises:
Responses:
Performs no actions in its body
for loop
(Matching)
4.9/5
(37)

​What are the three sections inside the parentheses of a for loop typically used for?

(Essay)
4.9/5
(35)

In a do…while loop, the loop will continue to execute until ____.

(Multiple Choice)
4.7/5
(42)

It is important that the loop control ____ be altered within the body of the loop.

(Multiple Choice)
4.8/5
(40)

How could you rewrite the following code to have the arithmetic performed only once, even if the loop executes 1,000 times? while (x < a + b) // loop body

(Essay)
4.7/5
(38)
Match each term with the correct statement below.
Premises:
Within parentheses are three sections separated by exactly two semicolons
Responses:
loop fusion
binary operators
data validation
Correct Answer:
Verified
Premises:
Responses:
Within parentheses are three sections separated by exactly two semicolons
loop fusion
(Matching)
4.8/5
(30)
Showing 1 - 20 of 77
close modal

Filters

  • Essay(0)
  • Multiple Choice(0)
  • Short Answer(0)
  • True False(0)
  • Matching(0)