CSC 10 Chapter 5

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

True or False. A condition-controlled loop always repeats a specific number of times.

False

True or False. It is not necessary to initialize accumulator variables.

False

True or False. It is not possible to increment a counter variable by any value other than 1.

False

True or False. The Do-While loop is a pretest loop.

False

True or False. In a nested loop, the inner loop goes through all of its iterations for every single iteration of the outer loops.

True

True or False. To calculate the total number of iterations of a nested loop, add the number of iterations of all the loops.

False

True or False. You cannot display the contents of the counter variable in the body of a loop.

False

A(n) ______ variable keeps a running total. a. sentinel b. sum c. total d. accumulator

d. accumulator

Each repetition of a loop is known as a(n) ______. a. cycle b. revolution c. orbit d. iteration

d. iteration

A For loop looks like what other loop in a flowchart?

While loop

True or False. The While loop is a pretest loop

True

Why should you indent the statements in the body of a loop?

By indenting the that statements in the body of the loop you visually set them apart from the surrounding code. This makes your program easier to read and debug. Also, this is similar to the style that most programmers follow when writing loops in actual code.

The For loop is a ______ type of loop. a. pretest b. posttest c. prequalified d. post iterative

a. pretest

What is a condition-controlled loop?

A condition-contrlled loop uses a true/false condition to control the number of times that it repeats.

What is a count-controlled loop?

A count-controlled loop iterates a specific number of times.

Why must the value chosen for use as a sentinel be carefully selected?

A sentinel value must be unique enough that it will not be mistaken as a regular value in the list.

What is an infinite loop? Write the code for an infinite loop.

An infinite loop continues to repeat until the program is interrupted. Infinite loops usually occur when the programmer forgets to write code inside the loop that makes the test condition false. Declare Integer awesome = 5 While awesome > 0 set awesome = awesome + 1 display awesome End While

What three actions do count-controlled loops typically perform using the counter variable?

Initialization, Test, and Increment

Describe the difference between pretest loops and posttest loops.

Pretest loops tests its condition before performing an iteration. Because the test is done at the beginning of the loop, you usually have to perform some steps prior to the loop to make sure that the loop executes at least once. Posttest loops performs an iteration before testing its condition. The posttest loop always perform at least once iteration even if its condition is false to begin with.

True or False. The following statement decrements the variable x: Set x = x - 1.

True

True or False. You should not write code that modifies the contents of the counter variable in the body of a For loop.

True

What is the advantage of using a sentinel?

When processing a long list of values with a loop, perhaps a better technique is to use a sentinel. A sentinel is a special value that marks the end of a list of items. When a program reads the sentinel value it knows it has reached the end of the list, so the loop terminates.

Why is it critical that accumulator variables are properly initialized?

When the loop finishes, the accumulator will contain the total of the numbers that were read by the loop. This is a critical step. Each time the loop reads a number, it adds it to the accumulator. If the accumulator starts with any value other than 0, it will not contain the correct total when the loop finishes.

A(n) ______ is a special value that signals when there are no more items from a list of items to be processed. This value cannot be mistaken as an item from the list. a. sentinel b. flag c. signal d. accumulator

a. sentinel

A ______-controlled loop uses a true/false condition to control the number of times that it repeats. a. Boolean b. condition c. decision d. count

b. condition

A ______ loop always executes at least once. a. pretest b. posttest c. condition-controlled d. count-controlled

b. posttest

The Do-While loop is a ______ type of loop. a. pretest b. posttest c. prequalified d. post iterative

b. posttest

A(n) ______ loop has no way of ending and repeats until the program is interrupted. a. indeterminate b. interminable c. infinite d. timeless

c. infinite

A ______-controlled loop repeats a specific number of times. a. Boolean b. condition c. decision d. count

d. count

The While loop is a ______ type of loop. a. pretest b. posttest c. prequalified d. post iterative

a. pretest


Kaugnay na mga set ng pag-aaral

NMIX 2020: Topics and Case Studies Group 1 (Apple, Smartphones, The Cloud + Big Data)

View Set

3.7 Orbital Diagrams (Chemistry)

View Set

Chapter 53: Assessment of Kidney and Urinary Function

View Set

warning signs of abusive relationships

View Set

Eng 201 Test 1, SLUH Odyssey 25 questions, KSU English 2110 Kerfoot Exam 1 Study Guide- terminology, Epic of Gilgamesh, World Lit Exam 1, English 2110, World Literature I Midterm practice (English 2111), World Lit Exam 1 (Epic of Gilgamesh + The Odys...

View Set

Block 2 Pathology Test 1 Chapter 8 Rickets and Osteomalacia

View Set

Network Security Modules 5-7: Monitoring and Managing

View Set