Repetition part 1 Flashcards

1
Q

Pseudo Code

A

fake code

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

write me a sentinel loop that add all the numbers tgt

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

Loop in a branch example

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

Branch in a loop example

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

end=” “ vs end=””

A

1 odd and 1odd

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

’<’ not supported between

A

instances of ‘str’ and ‘int’

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

wrire a code that adds all the sum of the number u enter before it. For ex: enter 4 (1+2+3+4)

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

When there is no branching/loops, the code runs….

A

Top to bottom (Sequential)

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

whether or not a part of the program repeats is determined by

A

a loop control

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

For loops: (2)

What it can do

A
  • can count through a numerical sequence (1,2,3)
  • iterate the sequence of characters in a string
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

For loops can only count trhough a

A

mumerical sequence through a sequence of addition or subtraction

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

While loop (2)

when it can be used

A

can be used any time repetition is needed
- can be used if its not know in advance how many times that loop will repeat

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

give me a countdown while loop example:

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

you cannot implement —– in For loop

A

logic

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

The only mathmatical operation you can do with For loop is

A

addition/subtraction

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

give me a countdown for loop

A
17
Q

Erroneous FOR loops (2)

What it is +ex

A

the logic of the loop is sucg tgat the end condition has already been reached with the start condition
- ex: when the programmer combine a loop that combines counting up with a loop that counts down

18
Q

while loop counting up/down pseudo code

A

starting value
end value
counting up/down by

19
Q

Sentinel controlled loops

when does it stop?

A

the stopping consition for the loop occurs when the sentinel value is reached (less then 0)

20
Q

Post Test Loops (3)

Python+when to use (2)?

A
  • python doesnt have one
  • used if you need a loop to always execute at least once even if the Boolean expression evaluated to false the first time that the loop is encountered.
  • You want to check the body of the loop before checking the stopping condition
21
Q

Post test loop are guaranteed execution because:

A

The Boolean expression is checked after the body executes

22
Q

Give me an example of a post test loop

A
23
Q

How to make a post test loop

A
  • prime the loop control so its guarantee execution

Ex: age<1 (LOOP CONTROL)
while (age<0)
print(“Type in answer”)

24
Q

Pre- test loop

When is it used?

A
  • you want the stopping condition to be checked before the loop body is executed (Used when you want a loop to execute zero or more times)
25
Q

Pre- test loop executes

+ ex:

A

zero or more times
age = 12
while (age< 0):