chap 4 - revisited Flashcards

1
Q

what is a conditional?

A

conditionals are if else statements that must be met in order for something to take place.

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

when using a conditional with multiple if statements then how do the else statements interact with those if statements?

A

the else automatically associates with the most recently used if statement.
..to force an else statement to work with a prior if statement then we must use ( ) around the nested if statements so that they dont associate with the else statement.
example:
if (argument here)
if (argument here)
else (*output here);
^^the else statement will work with the second if statement and not the 1st unless we put ( ) around the second nested if statement.

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

what are nested if statements?

A

when an if statement is followed by another if statement before an else statement.

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

what is the structure of an If statement?

A

If statement:
if –> conditional –> statement

conditional uses boolean arguments often.

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

example of a conditional where the variable conditional is less than 17
then print to the screen “the conditions have been met”

A

if (conditional < 17)

System.out.println(“The conditions have been met”);

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

when using a conditional is there a way to have operators for: and .. or statements?

A

yes the operators used:
&& and
|| OR

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

block statement? is what?

A

block statement:

group of statements and declarations deliminated (within) braces { }.

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

what are nested if statements?

A

nested if statements:

an if condition with another if statement within its body.

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

when using nested if statements does the else statement line up with the first if ?

A

the else statement always matches up with the closest unmatched if statement unless ( ) are used to force otherwise.

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

how to stop an infinite loop in a program what do you do?

A

press CTRL + C

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

what is the format of a while loop?

A

while (boolean argument)
{ what happens such as adding one
This is the body of the loop that is executed until the boolean is met.}

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

what is an infinite or endless loop?

A

an error where a while loop never ends due to a logic error.

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

what are the sections of a for loop? (3)

A

initialization – initializes a variable with a value
Condition – basically a boolean
increment — the variable with ++ one added on,

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

what are the sections of a for loop? (3)

A

initialization – initializes a variable with a value
Condition – a boolean
increment — the variable with ++ one (or other amount) added on After
The body of the loop is executed each time.

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