Week 10 Part 2 Flashcards

1
Q

o Decision structures are meant to perform (or not perform) set(s) of statements ____, repetition structures are only used to perform one set of statement ________

A

 Once, repeatedly

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

o A while loop is the ______ loop

A

 simplest

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

o If the Boolean result is false for a while loop before it begins

A

 The body is skipped over and never executed

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

o What is the best loop if you are not sure how many times the loop will need to repeat?

A

 While loop

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

o A difference between a while loop and a do-while loop is that in a do while loop the body of the expression will always

A

 Execute at least once

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

o Unlike other loops, this loop requires a semicolon after the condition

A

 Do-while loop, as no brace comes afterwards

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

o When are for loops best used?

A

 Counted loops where you know how many repetitions are needed

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

o The parts in the parenthesis of a for loop are optional, other than the ; . What happens if all parts are omitted?

A

 You will get an infinite loop

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

o Will this run?
o For( ; index < 42 ; ){
index++; }

A

o Yes, works like a while loop (don’t do this though)

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

o Just like if statements the _____ are optional if there’s only 1 statement. This is also a common mistake with loops

A

 Braces

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

o What happens if we run these?
 For (expression) ; {}
while(expression);{}

A

 Infinite loop

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

o A block of code is typically outlined with

A

 {}

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

o Loops count as _____ code and variables inside them have a _____-_____ scope

A

 Block, block-level

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

o It’s best practice to use _____ _____ variables whenever possible in all cases

A

 Local scope

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

o The _____ and ________ keywords are controversial in java

A

 Break and continue

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

o Break and continue can be used with _________ and _____. You usually see both of them ______ inside of ____

A

 Decisions and loops, nested, loops

17
Q

o The break keyword is typically used to

A

 End a loop early

18
Q

o In a loop, the continue keyword

A

 Causes the loop to return to the top, skipping any statements that were remaining within the loop

19
Q

o Labelled break and continue are rarely used, they are very controversial as they break the tenants of __________ ___________

A

 Structured programming

20
Q

o Identify this
o for(data_type variable : array_or_collection){
// statement(s)
}

A

 Enhanced for loop