Chapter 5 Flashcards

0
Q

List the various types of while loops.

A
  1. Counter-Controlled while loop
  2. Sentinel-controlled while loop
  3. Flag-controlled while loop
  4. EOF (end of file) controlled while loop
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
1
Q

What is an Infinite loop?

A

A loop whose execution continues forever.

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

Define Counter-controlled while loop.

A

Used when you know exactly how many times you need the loop to execute.

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

Define Sentinel-controlled while loop.

A

Uses a sentinel: a special value that can be used to indicate the end of processing. Used to control the loop.

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

Define Flag-controlled while loop.

A

Used Boolean variable to control the loop.

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

Define EOF (End of File) controlled while loop:

A

Loops while there is still data to be read in from the input file.

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

What is a for-loop?

A

A specialized form of the While loop. It’s primary purpose is to simplify the writing of counter-controlled loops. Used for counting.
(Pre-test loop)

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

Code for While loop

A

While (expression)
Statement

Example:

While (Price != -1)
{
Statement
}

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

Code for For Loops.

A

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

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

Code for Do While loops.

A
do
{
statement (aka code)
}
while (expression);

(Post-test loop)

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

What is a post test loop?

A

Loop always executes at least once

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

What is a pre-test loop?

A

Tests loop condition before executing loop instructions.

It is possible that the loop instructions will never execute.

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

When to use a While loop.

A

The example we used calculated tax and had the option to type “-1” and end the loop.

While(price != -1)

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

When to use a For loop.

A

Used for counting.

Example used in notes:
“create a program that will print out all of the even numbers within a range that the user specifies”

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

When to use a do while loop

A

Couldn’t find anything. Look at program on N drive.

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

Study nested loop worksheet

A

Study the worksheet