Exam 6: Looping

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

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

(True/False)
4.7/5
(35)

How are nested loops implemented in a loop structure?

(Essay)
4.7/5
(40)

Many seasoned programmers start counter values at 1 because they are used to doing so when working with arrays.

(True/False)
4.9/5
(43)

What are some unconventional uses of the three sections inside the parentheses of a  for loop? Show at least three examples using code.

(Essay)
4.8/5
(37)

How does a for loop work?

(Essay)
4.9/5
(38)

Which of the following is NOT a valid method to increase a variable named score by 1?

(Multiple Choice)
4.8/5
(34)

The ____________________ loop is the posttest loop used in Java.

(Short Answer)
4.8/5
(42)

A loop that never ends is called a(n) ____ loop.

(Multiple Choice)
4.8/5
(44)

public class IncrDemo {     public static void main(String[] args)     {       int myVal, yourVal;       myVal = 10;       System.out.println("My initial value is " + myVal);       yourVal = ++myVal;       System.out.println("My new value is " + myVal);       System.out.println("Your value is " + yourVal):     } } Using the above code, describe how the three println output commands will appear. Explain the values stored in the variables during code execution.

(Essay)
4.8/5
(45)

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 .

(Multiple Choice)
4.7/5
(33)

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

(Essay)
4.9/5
(39)

Why would a programmer use curly braces in the body of a do…while loop?

(Essay)
4.8/5
(30)

public class DoWhileExample {     public static void main(String[] args)     { int currentValue; ____ ____ ____ ____ ____     } } Complete the code above by writing a do…while posttest loop that will output the value of the variable currentValue in a println statement. After the output statement, add a decrement statement to decrease the value of currentValue by 1. Continue the loop until currentValue is equal to 0.

(Essay)
4.9/5
(34)

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

(Multiple Choice)
4.9/5
(31)

When loops are nested, each pair contains a(n) ____________________ loop and an outer loop.

(Short Answer)
4.9/5
(40)

Programmers rarely use indefinite loops when validating input data.

(True/False)
4.8/5
(39)

You use a unary minus sign preceding a value to make the value ____.

(Multiple Choice)
4.9/5
(44)

Provide a code example of a pretest loop and an example of a posttest loop.

(Essay)
4.7/5
(41)

An indefinite loop is a(n) ____ loop.

(Multiple Choice)
4.7/5
(36)

Create an indefinite while loop that will validate that the loop control variable named userNum is less than the constant MAXVALUE . While true, create a println statement to output "Please enter a higher value". Get user input of another value for userNum after each println statement. Once MAXVALUE is reached, create a final println statement that will output "Max value reached".

(Essay)
4.9/5
(39)
Showing 21 - 40 of 66
close modal

Filters

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