Module 3 (Prelim) Flashcards

3.1 Overview 3.2 Loop Structure 3.3 while Loop 3.4 Increment and Decrement Operators 3.5 for Loop 3.6 do...while Loop 3.7 Nested Loops 3.8 break and continue Statements

1
Q

A structure that allows repeated execution of a block of statements

A

Loop

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

A block of statements that are executed repeatedly

A

Loop body

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

One execution of any loop

A

Iteration

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Three types of loops

A

while
for
do…while

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

The loop-controlling Boolean expression is the first statement

A

while

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

A concise format in which to execute loops

A

for

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

The loop-controlling Boolean expression is the last statement

A

do…while

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Executes a body of statements continually. As long as the Boolean expression that controls entry into the loop continues to be true

A

while loop

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

while loop syntax:

A

while (expression)
….statement

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Performs a task a predetermined number of times

A

Definite loop or counter-controlled loop

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Definite loop or counter-controlled loop is also called _________

A

counted loop

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Sentinel variable is tested in the condition. Loop ends when sentinel is encountered

A

Indefinite or Sentinel-controlled while loops

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

A loop that never ends. Can result from a mistake in the while loop

A

Infinite loop

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Suspect an infinite loop when:

A

-The same output is displayed repeatedly
-The screen remains idle for an extended period of time

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

To exit an infinite loop:

A
  • press and hold Ctrl + C
  • Break
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

is an operator used for one value

A

unary operators

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q
  • The result is calculated and stored
  • Then the variable is used
A

Prefix ++

18
Q
  • The variable is used
  • Then the result is calculated and stored
A

Postfix ++

19
Q

Prefix and postfix increment operators

A

++someValue and someValue++

20
Q

Prefix and postfix decrement operators

A

–someValue and someValue–

21
Q

The expression (x++) simply means______

A) add 1 to x and return the old value (Postfix increment)
B) add 1 to x and return the new value (Prefix increment)
C) take 1 from x and return the old value (Postfix decrement)
D) take 1 from x and return the new value (Prefix decrement)

A

A) add 1 to x and return the old value

22
Q

The expression (++x) simply means______

A) add 1 to x and return the old value (Postfix increment)
B) add 1 to x and return the new value (Prefix increment)
C) take 1 from x and return the old value (Postfix decrement)
D) take 1 from x and return the new value (Prefix decrement)

A

B) add 1 to x and return the new value

23
Q

The expression (–x) simply means______

A) add 1 to x and return the old value (Postfix increment)
B) add 1 to x and return the new value (Prefix increment)
C) take 1 from x and return the old value (Postfix decrement)
D) take 1 from x and return the new value (Prefix decrement)

A

D) take 1 from x and return the new value

24
Q

The expression (x–) simply means______

A) add 1 to x and return the old value (Postfix increment)
B) add 1 to x and return the new value (Prefix increment)
C) take 1 from x and return the old value (Postfix decrement)
D) take 1 from x and return the new value (Prefix decrement)

A

C) take 1 from x and return the old value

25
Q

Used when a definite number of loop iterations is required

A

for Loop

26
Q

for Loop syntax:

A

for (initial statement; loop condition; update statement)
statement

27
Q

The initial statement, loop condition, and update statement are called ________

A

for loop control statements

28
Q

Other uses for the three sections of a for loop:

A
  • Initialization of more than one variable
  • Performance of more than one test using AND or OR operators
  • Decrementing or performance of some other task
  • Altering more than one value
29
Q

You can leave one or more portions of a for loop empty
(True or False)

A

T

Two semicolons are still required as placeholders

30
Q

For loop:
- To pause a program: (2)

A
  • Use do-nothing loop (ex. for(x = 0; x < 100000; ++x);)
  • use the built-in sleep() method
31
Q

is a posttest loop

A

do…while loop

32
Q

The statement executes first, and then the expression is evaluated. As long as expression is true, loop continues. Loop always iterates at least once

A

do…while Loop

33
Q

do…while Loop:
To avoid an infinite loop, body must contain a statement that makes the expression ________

A

false

34
Q

do…while Loop syntax:

A

do
{
statement
}
while (expression)

35
Q

An inner loop must be entirely contained in an outer loop
(True or False)

A

T

36
Q

______and ______ alter the flow of control

A

break
continue

37
Q

break statement is used for two purposes:

A
  • To exit early from a loop
  • To skip the remainder of a switch structure
38
Q

break and continue Statements:

After ______ executes, the program continues with the first statement after the structure

A

break

39
Q

continue is used in while, for, and do…while structures
(True or False)

A

T

40
Q

When __________ is executed in a loop, It skips remaining statements and proceeds with the next iteration of the loop

A

break and continue