Chapter 12 Flashcards

1
Q

If you wanted to repeat code over and over again what is it that you need in a program? And what is the basic format for this element?

A

In order to repeat statements over and over again you need something called a while statement also known as a while loop and the basic format goes like this:
while (condition) {
some statements
}

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

What part of the while loop is repeated over and over again?

A

The stuff that’s in between curly braces:

while (condition) {
Some statements
}

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

In a while loop what has to be met in order for the statements to be repeated over and over again?

A

The condition must be true in a while statement in order for the statements to be repeated over and over again

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

What is the results of running this while loop?

While( die1 + die2 != 7 && die1 + die2 != 11)

A

The results would be an iteration of loops until one of the dice hit 7 or 11

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

In order for this while loop to stop what needs to happen?
While( die1 + die2 != 7 && die1 + die2 != 11)

What happens if part of the condition is true while the other part is false

A

Both pieces of the condition must not equal seven or 11.

If the condition is false or partly false then when the Java program is run it will continue to iterate loops until it hits 7 or 11

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

Is similar to a while statement? What can be added to the statement within the curly braces of a while loop?

A

A while loop can contain one statement or several statements and more than one statement is called a compound statement

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

When a while loop and an if statement contains more than one statement within the curly braces what is this called ?

A

When multiple statements are within the curly braces of a while loop or an if statement this is called a block and it performs as one big statement or compound statements

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

During a while loop as it performs iterations when does it jump out of the loop to continue the rest of the code?

A

Depending on the condition once the condition is met then it’ll jump out of the loop

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

How do you stop a loop from performing an infinite amount of iterations or code from continuing to run without stopping?

A

There is a rectangular red button in the console view and when you hover your cruiser over it it displays terminate so click that button and it will stop any code dead in its tracks

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

In what occasion should you have code that continues to run continuously?

A

A heart rate monitor a lung breathing machine etc etc

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

How do you insert a tab in your code in between quote marks without pressing the tab key? And what is the name of this option?

A

Wherever you need a tab just type \t inside double quotes marks this is an example of what is called an escape sequence

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

What are two examples of an escape sequence? What escape sequence do you use to jump to a new line in between double quote marks?

A

Two examples of escape sequences are \t which jumps a tab in between double quote marks and \n which jumps to a new line and can be a substitute for System.out.println(“”)
System.out.print(“\n”)

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

When it comes to writing your code and the order of how it should be displayed in order to run correctly what’s one thing to keep in mind?

A

Depending on the program you’re trying to build you might want to write out the test part of the program first followed by the input and last to print. It just depends on the program you’re trying to build whatever makes sense you would start off with that component first like input print and then test

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