chap 4 - revisited Flashcards Preview

Java 1 > chap 4 - revisited > Flashcards

Flashcards in chap 4 - revisited Deck (14)
Loading flashcards...
1

what is a conditional?

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

2

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

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.

3

what are nested if statements?

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

4

what is the structure of an If statement?

If statement:
if --> conditional --> statement

conditional uses boolean arguments often.

5

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

if (conditional < 17)
System.out.println("The conditions have been met");

6

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

yes the operators used:
&& and
|| OR

7

block statement? is what?

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

8

what are nested if statements?

nested if statements:
an if condition with another if statement within its body.

9

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

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

10

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

press CTRL + C

11

what is the format of a while loop?

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

12

what is an infinite or endless loop?

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

13

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

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

14

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

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.