Loops Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

Write the While Loop Structure

A

while(somecondition){
//repeat code in the squiggly brackets if the condition is true
}

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

As long as the condition is true in the ( ) of loop conditions, the code in the { } will repeat ______

A

indefinetly

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

What conditions can be placed in the ( ) of while loops?

A

same conditions used in if statements

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

What will this code do:

int intNumber;

intNumber = 3

while (intNumber <= 5){
con.println(“Wahoo”);
}

A

print “Wahoo” indefinetly

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

What will this code do:

intNumber = 5;

while (intNumber <= 5){
con.println(“Wahoo”);
}

A

print Wahoo indefinetly

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

What will this code do:

intNumber = 10;

for (intNumber <= 5){
con.println(“Wahoo”);
}

A

print nothing

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

Function of the Looping Structures

A

repeat whatever is in the { } as long as the condition is true

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

repeat whatever is in the { } as long as the condition is true

A

Function of the Looping Structures

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

When do loops (while/for) stop repeating?

A

Once condition inside ( ) is false

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

Function of Inatializing Variables

A

to give variables default values

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

number variables are usually initialized to ______

A

0

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

string variables are usually intialized to _____

A

empty double quotes (i.e. “”)

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

to give variables default values

A

Function of Initializing Variables

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

Write the code to check if a string does NOT include certain characters

A

!strVariable.equalsIgnoreCase(“xxx”)

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

Function of:

!strVariable.equalsIgnoreCase(“xxx”)

A

checks if a string does NOT include certain characters

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

Write the general structure of a for loop statement

A

for(intCount = #; intCount [math comparison symbol] #; intCount++/–){
// repeat code if condition is true, until it is false
}

17
Q

increment symbol

A

++

18
Q

++

A

increment symbol

19
Q

_ _

A

decrement symbol

20
Q

decrement symbol

A

_ _

21
Q

3 Parts in a For Loop Condition

A
  1. Intialize Variable to Default Value
  2. Condition Check
  3. Count Up (Increment) or Count Down (Decrement)
22
Q

statements that are done once are placed…

A

outside the { }

23
Q

What does this code do:

dblTotal = dblTotal + dblNumber;

A

add the old value in dblTotal to dblNumber
input the result to dblTotal, giving it a new value

24
Q

.length();

A

measures the length of any string

25
Q

string logic comparison which measures the length of a string

A

.length();

26
Q

Function of:

strVariable2 + strVariable1

A

attaches (concatenating) two strings together
i.e. a + b = ab

27
Q

Function of (int) in the following code:

intRand = (int)(Math.random()*100 + 1);

A

Casting… forces the double to be an integer
- cuts off the decimals

28
Q

Function of Math.random()

A

generates dbl numbers between 0.0000000-0.999999999

29
Q

Write code which prints random ingeters between 1-100

A

int intRandom;

intRandom = (int)(Math.random()* 100+1);
con.println(intRandom);

30
Q

Write a program that prints the largest of five entered numbers (using if statements or Math.max()).

A