Chapter 6: Loops Flashcards

1
Q

Loops

A

a program construct that repeatedly executes the loop’s statements (known as the loop body) while the loop’s expression is true; when false, execution proceeds past the loop.

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

Iteration

A

Each time through a loop’s statements

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

While Loop

A

a construct that repeatedly executes an indented block of code (known as the loop body) as long as the loop’s expression is True.

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

Sentinel Value

A

a value that when evaluated by the loop expression causes the loop to terminate.

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

f’

Ex. print(f’something)

A

(STILL NEED A DEFINITION!)

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

Infinite Loop

A

a loop that will always execute because the loop’s expression is always True. (Usually want to avoid these)

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

,end=”\n”

A

default of the end of a print statement.

The thing that goes in between the quotations is what goes in between the next print statement(s)

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

randint()

A

A function that provides a new random number

You can make a range by providing the min, max

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

Loop Variable

A

Where a programmer uses a variable to count the number of iterations.

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

range(x, y, z)

A

a range function where:
x = first number(inclusive) (optional)(Default is 0)
y = ending number(exclusive)
z = integer step value/ increment (optional)(Default is 1)

can go backwards:
Ex: range(5, -5, -1)
-1 specifies that it goes downward

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

When To Use:

For vs While Loop

A

For Loop:
Use when you are given a number of iterations

While Loop:
Use when you are not given a number of iterations

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

Nested Loop

A

A loop inside of another loop

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

chr()

A

converts into a character; not a string

character is like string but can only hold one space

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

How to make rows and columns

A
num_rows = int(input())
num_cols = int(input())

for i in range(num_rows):
for i in range(num_cols):

    print('*', end=' ')
print()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

break

A

a statement that causes the loop to exit immediately.

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

continue

A

a statement that causes an immediate jump to the while or for loop header statement

17
Q

else:

A

Will run if an if and elif statements are false

Will also run after a for loop if there isn’t a break