Deck 6: Looping

ملء الشاشة (f)
exit full mode
سؤال
Programmers rarely use indefinite loops when validating input data.
استخدم زر المسافة أو
up arrow
down arrow
لقلب البطاقة.
سؤال
On many keyboards, the Break key is also the ____ key.

A) Pause
B) Esc
C) Delete
D) Ctrl
سؤال
Many seasoned programmers start counter values at 1 because they are used to doing so when working with arrays.
سؤال
You can use virtually any number of nested loops; however, at some point, your machine will no longer be able to store all the necessary looping information.
سؤال
Shortcut operators are a programmer's only choice when incrementing or accumulating a variable's value.
سؤال
Making a comparison to 0 is slower than making a comparison to any other value.
سؤال
Altering a variable within both a for statement and within the block it controls can produce errors that are difficult to find.
سؤال
A ____ is a structure that allows repeated execution of a block of statements.

A) body
B) Boolean expression
C) loop
D) loop control
سؤال
____ is the process of ensuring that a value falls within a specified range.

A) Value checking
B) Data integrity
C) Validating data
D) A range check
سؤال
Use a(n) ____ loop to execute a body of statements continually as long as the Boolean expression that controls entry into the loop continues to be true.

A) empty
B) while
C) definite
D) control
سؤال
A loop controlled by the user is a type of ____ loop.

A) indefinite
B) definite
C) counter-controlled
D) incrementing
سؤال
A statement that will alter the value of the loop control variable is included in the body of a loop.
سؤال
Which is an infinite loop?

A) loopCount = 5;
While(loopCount > 3);
{
System.out.println("Hello");
LoopCount = loopCount - 1;
}
B) loopCount = 1;
While(loopCount < 3);
{
System.out.println("Hello");
}
C) loopCount = 4;
While(loopCount < 3);
{
System.out.println("Hello");
LoopCount = loopCount + 1;
}
D) loopCount = 1;
While(loopCount < 3);
{
System.out.println("Hello");
LoopCount = loopCount + 1;
}
سؤال
An indefinite loop is a(n) ____ loop.

A) counter-controlled
B) event-controlled
C) initialized
D) validating
سؤال
In order to improve loop performance, it's important to make sure the loop does not include unnecessary operations or statements.
سؤال
The statements that make up a loop body will continue to execute as long as the expression value remains false.
سؤال
It is important that the loop control ____ be altered within the body of the loop.

A) value
B) variable
C) constant
D) argument
سؤال
A loop that never ends is called a(n) ____ loop.

A) definite
B) infinite
C) while
D) for
سؤال
When nesting loops, the variable in the outer loop changes more frequently.
سؤال
Before entering a loop, the first input, or ____, is retrieved.

A) empty body
B) posttest loop
C) loop body
D) priming read
سؤال
The ____________________ loop is the posttest loop used in Java.
سؤال
The process of repeatedly increasing a value by some amount is known as ____.

A) checking
B) adding
C) accumulating
D) containing
سؤال
A(n) ____ loop is one that performs no actions other than looping.

A) nested
B) do-nothing
C) indefinite
D) posttest
سؤال
The ____ loop checks the value of the loop control variable at the bottom of the loop after one repetition has occurred.

A) while
B) do…while
C) for
D) else
سؤال
In the expressions b = 8 and c = --b, what value will be assigned to the variable c?

A) 8
B) 7
C) 9
D) 10
سؤال
You can initialize more than one variable in a for loop by placing a(n) ____ between the separate statements.

A) semicolon
B) equal sign
C) period
D) comma
سؤال
The order of the conditional expressions in the following is most important within a(n) ____ loop. while(requestedNum > LIMIT || requestedNum < 0)…

A) nested
B) posttest
C) pretest
D) indefinite
سؤال
As long as methods do not depend on one another, ____ is a technique that can improve loop performance by combining two loops into one.

A) loop fusion
B) prefix incrementing
C) short-circuit evaluation
D) do-nothing looping
سؤال
Which of the following is NOT a valid method to increase a variable named score by 1?

A) ++score
B) score++
C) ++score = score + 1
D) score = score + 1
سؤال
In a do…while loop, the loop will continue to execute until ____.

A) the loop control variable is true
B) the loop control variable is false
C) the user types EXIT
D) the program terminates
سؤال
When loops are nested, each pair contains a(n) ____________________ loop and an outer loop.
سؤال
If a(n) ____________________ is altered both within the for statement and within the block it controls, it can be very difficult to follow the program's logic.
سؤال
One execution of any loop is called a(n) ____________________.
سؤال
You use a unary minus sign preceding a value to make the value ____.

A) negative
B) positive
C) valid
D) constant
سؤال
When creating a for loop, which statement will correctly initialize more than one variable?

A) for a=1, b=2
B) for(a=1; b=2)
C) for(a=1, b=2)
D) for(a = 1&& b = 2)
سؤال
When you want to increase a variable's value by exactly 1, use the ____.

A) power statement
B) accumulating operator
C) binary operators
D) prefix increment operator
سؤال
How many times will outputLabel be called? for(customer = 1; customer <= 20; ++customer)
For(color = 1; color <= 3; ++color)
OutputLabel();

A) 0
B) 3
C) 20
D) 60
سؤال
A(n) ____________________ is a body with no statements in it.
سؤال
A for loop provides a convenient way to create a(n) ____ loop.

A) counter-controlled
B) posttest
C) while
D) infinite
سؤال
A(n) ____ loop is a special loop that is used when a definite number of loop iterations is required.

A) while
B) for
C) else
D) do…while
سؤال
Why would a programmer use curly braces in the body of a do…while loop?
سؤال
Why would a loop with altered user input be considered a type of indefinite loop? Give an example.
سؤال
Match each term with the correct statement below.
a.prefix ++
f.loop fusion
b.block
g.decrementing
c.definite loop
h.for loop
d.loop control variable
i.sleep() method
e.binary operators
A shortcut for incrementing and accumulating
سؤال
Match each term with the correct statement below.
a.prefix ++
f.loop fusion
b.block
g.decrementing
c.definite loop
h.for loop
d.loop control variable
i.sleep() method
e.binary operators
The value that determines whether loop execution continues
سؤال
Describe the purpose of a loop control variable. How are Boolean values and a while loop involved?
سؤال
Besides initializing, testing, and incrementing, you can also perform other tasks with a for loop. What are some of these tasks? Use code samples as examples.
سؤال
What would happen if a semicolon is mistakenly placed at the end of a partial statement of a while loop with a Boolean expression and with an empty body?
سؤال
Match each term with the correct statement below.
a.prefix ++
f.loop fusion
b.block
g.decrementing
c.definite loop
h.for loop
d.loop control variable
i.sleep() method
e.binary operators
Subtracting 1 from a variable
سؤال
Match each term with the correct statement below.
a.prefix ++
f.loop fusion
b.block
g.decrementing
c.definite loop
h.for loop
d.loop control variable
i.sleep() method
e.binary operators
Part of the Thread class in the java.lang package
سؤال
How does a for loop work?
سؤال
Match each term with the correct statement below.
a.prefix ++
f.loop fusion
b.block
g.decrementing
c.definite loop
h.for loop
d.loop control variable
i.sleep() method
e.binary operators
Within parentheses are three sections separated by exactly two semicolons
سؤال
How are nested loops implemented in a loop structure?
سؤال
How could a programmer identify and escape from an infinite loop?
سؤال
Match each term with the correct statement below.
a.prefix ++
f.loop fusion
b.block
g.decrementing
c.definite loop
h.for loop
d.loop control variable
i.sleep() method
e.binary operators
Multiple statements within curly braces
سؤال
Match each term with the correct statement below.
a.prefix ++
f.loop fusion
b.block
g.decrementing
c.definite loop
h.for loop
d.loop control variable
i.sleep() method
e.binary operators
The technique of combining two loops into one
سؤال
How could you rewrite the following code to have the arithmetic performed only once, even if the loop executes 1,000 times?
while (x < a + b)
// loop body
سؤال
Match each term with the correct statement below.
a.prefix ++
f.loop fusion
b.block
g.decrementing
c.definite loop
h.for loop
d.loop control variable
i.sleep() method
e.binary operators
Operate on two values
سؤال
What are some of the shortcuts Java provides programmers for incrementing and accumulating? Give examples of statements.
سؤال
Describe how a loop is controlled by a Boolean expression.
سؤال
Match each term with the correct statement below.
a.prefix ++
f.loop fusion
b.block
g.decrementing
c.definite loop
h.for loop
d.loop control variable
i.sleep() method
e.binary operators
A counter-controlled loop
سؤال
Explain why an infinite loop might not actually execute infinitely.
سؤال
How are indefinite loops used for validating data? Why is a loop structure typically the better choice for validating data than an if statement?
سؤال
Write a definite while loop that initializes a loop control variable named decreaseOne to 10 and continues until decreaseOne > 0. Decrement the loop control variable by 1 and include the println output "Keep going" within the loop.
سؤال
counterLoop = 1;
while(counterLoop < 10);
{
System.out.println("Enter a new value");
counterLoop = counterLoop + 1;
}
What is the problem in the above while loop? How would you correct the problem?
سؤال
public class CompareValues
{
public static void main(String[] args)
{
int a = 10, b = 10, c = 11;
boolean compare1 = (++b == a);
boolean compare3 = (b++ == c);
System.out.println("Compare 1 value = " + compare1);
System.out.println("Compare 2 value = " + compare2);
}
}
Using the above code, what values will appear in compare1 and compare2 when the println commands execute? Describe how the values of compare1 and compare2 change as the statements are executed.
سؤال
while(10 > 1)
{
System.out.println("Enter a new value");
}
Identify the problem that exists in the above code.
سؤال
public class CaseDemo
{
public static void main(String[] args)
{
int myVal, yourVal;
myVal = 10;
System.out.println("My initial value is " + myVal);
yourVal = ++myVal;
System.out.println("My new value is " + myVal);
System.out.println("Your value is " + yourVal):
}
}
Using the above code, describe how the three println output commands will appear. Explain the values stored in the variables during code execution.
سؤال
Loop control variables can be evaluated at the start or the end of the loop. Describe both pretest loops and posttest loops. How do do…while loops execute?
سؤال
Describe a counter-controlled loop. Explain the process of incrementing and decrementing, and explain the best method for executing a loop a specific number of times.
سؤال
Create an indefinite while loop that will validate that the loop control variable named userNum is less than the constant MAXVALUE. While true, create a println statement to output "Please enter a higher value". Once MAXVALUE is reached, create a final println statement that will output "Max value reached".
سؤال
public class DoWhileExample
{
public static void main(String[] args)
{
int currentValue;
____
____
____
____
____
}
}
Complete the code above by writing a do…while posttest loop that will output the value of the variable currentValue in a println statement. After the output statement, add a decrement statement to decrease the value of currentValue by 1. Continue the loop until currentValue is equal to 0.
سؤال
Write a for loop that will initialize the variables value1 to 11 and value2 to 19. Create a test section of the for statement that will test if value1 is greater than 10 and value2 is less than 20. Finally, end the for statement by incrementing value1 by 1. In the loop body, write a println statement that will display the contents of value1.
فتح الحزمة
قم بالتسجيل لفتح البطاقات في هذه المجموعة!
Unlock Deck
Unlock Deck
1/72
auto play flashcards
العب
simple tutorial
ملء الشاشة (f)
exit full mode
Deck 6: Looping
1
Programmers rarely use indefinite loops when validating input data.
False
2
On many keyboards, the Break key is also the ____ key.

A) Pause
B) Esc
C) Delete
D) Ctrl
A
3
Many seasoned programmers start counter values at 1 because they are used to doing so when working with arrays.
False
4
You can use virtually any number of nested loops; however, at some point, your machine will no longer be able to store all the necessary looping information.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 72 في هذه المجموعة.
فتح الحزمة
k this deck
5
Shortcut operators are a programmer's only choice when incrementing or accumulating a variable's value.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 72 في هذه المجموعة.
فتح الحزمة
k this deck
6
Making a comparison to 0 is slower than making a comparison to any other value.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 72 في هذه المجموعة.
فتح الحزمة
k this deck
7
Altering a variable within both a for statement and within the block it controls can produce errors that are difficult to find.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 72 في هذه المجموعة.
فتح الحزمة
k this deck
8
A ____ is a structure that allows repeated execution of a block of statements.

A) body
B) Boolean expression
C) loop
D) loop control
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 72 في هذه المجموعة.
فتح الحزمة
k this deck
9
____ is the process of ensuring that a value falls within a specified range.

A) Value checking
B) Data integrity
C) Validating data
D) A range check
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 72 في هذه المجموعة.
فتح الحزمة
k this deck
10
Use a(n) ____ loop to execute a body of statements continually as long as the Boolean expression that controls entry into the loop continues to be true.

A) empty
B) while
C) definite
D) control
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 72 في هذه المجموعة.
فتح الحزمة
k this deck
11
A loop controlled by the user is a type of ____ loop.

A) indefinite
B) definite
C) counter-controlled
D) incrementing
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 72 في هذه المجموعة.
فتح الحزمة
k this deck
12
A statement that will alter the value of the loop control variable is included in the body of a loop.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 72 في هذه المجموعة.
فتح الحزمة
k this deck
13
Which is an infinite loop?

A) loopCount = 5;
While(loopCount > 3);
{
System.out.println("Hello");
LoopCount = loopCount - 1;
}
B) loopCount = 1;
While(loopCount < 3);
{
System.out.println("Hello");
}
C) loopCount = 4;
While(loopCount < 3);
{
System.out.println("Hello");
LoopCount = loopCount + 1;
}
D) loopCount = 1;
While(loopCount < 3);
{
System.out.println("Hello");
LoopCount = loopCount + 1;
}
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 72 في هذه المجموعة.
فتح الحزمة
k this deck
14
An indefinite loop is a(n) ____ loop.

A) counter-controlled
B) event-controlled
C) initialized
D) validating
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 72 في هذه المجموعة.
فتح الحزمة
k this deck
15
In order to improve loop performance, it's important to make sure the loop does not include unnecessary operations or statements.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 72 في هذه المجموعة.
فتح الحزمة
k this deck
16
The statements that make up a loop body will continue to execute as long as the expression value remains false.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 72 في هذه المجموعة.
فتح الحزمة
k this deck
17
It is important that the loop control ____ be altered within the body of the loop.

A) value
B) variable
C) constant
D) argument
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 72 في هذه المجموعة.
فتح الحزمة
k this deck
18
A loop that never ends is called a(n) ____ loop.

A) definite
B) infinite
C) while
D) for
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 72 في هذه المجموعة.
فتح الحزمة
k this deck
19
When nesting loops, the variable in the outer loop changes more frequently.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 72 في هذه المجموعة.
فتح الحزمة
k this deck
20
Before entering a loop, the first input, or ____, is retrieved.

A) empty body
B) posttest loop
C) loop body
D) priming read
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 72 في هذه المجموعة.
فتح الحزمة
k this deck
21
The ____________________ loop is the posttest loop used in Java.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 72 في هذه المجموعة.
فتح الحزمة
k this deck
22
The process of repeatedly increasing a value by some amount is known as ____.

A) checking
B) adding
C) accumulating
D) containing
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 72 في هذه المجموعة.
فتح الحزمة
k this deck
23
A(n) ____ loop is one that performs no actions other than looping.

A) nested
B) do-nothing
C) indefinite
D) posttest
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 72 في هذه المجموعة.
فتح الحزمة
k this deck
24
The ____ loop checks the value of the loop control variable at the bottom of the loop after one repetition has occurred.

A) while
B) do…while
C) for
D) else
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 72 في هذه المجموعة.
فتح الحزمة
k this deck
25
In the expressions b = 8 and c = --b, what value will be assigned to the variable c?

A) 8
B) 7
C) 9
D) 10
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 72 في هذه المجموعة.
فتح الحزمة
k this deck
26
You can initialize more than one variable in a for loop by placing a(n) ____ between the separate statements.

A) semicolon
B) equal sign
C) period
D) comma
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 72 في هذه المجموعة.
فتح الحزمة
k this deck
27
The order of the conditional expressions in the following is most important within a(n) ____ loop. while(requestedNum > LIMIT || requestedNum < 0)…

A) nested
B) posttest
C) pretest
D) indefinite
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 72 في هذه المجموعة.
فتح الحزمة
k this deck
28
As long as methods do not depend on one another, ____ is a technique that can improve loop performance by combining two loops into one.

A) loop fusion
B) prefix incrementing
C) short-circuit evaluation
D) do-nothing looping
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 72 في هذه المجموعة.
فتح الحزمة
k this deck
29
Which of the following is NOT a valid method to increase a variable named score by 1?

A) ++score
B) score++
C) ++score = score + 1
D) score = score + 1
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 72 في هذه المجموعة.
فتح الحزمة
k this deck
30
In a do…while loop, the loop will continue to execute until ____.

A) the loop control variable is true
B) the loop control variable is false
C) the user types EXIT
D) the program terminates
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 72 في هذه المجموعة.
فتح الحزمة
k this deck
31
When loops are nested, each pair contains a(n) ____________________ loop and an outer loop.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 72 في هذه المجموعة.
فتح الحزمة
k this deck
32
If a(n) ____________________ is altered both within the for statement and within the block it controls, it can be very difficult to follow the program's logic.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 72 في هذه المجموعة.
فتح الحزمة
k this deck
33
One execution of any loop is called a(n) ____________________.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 72 في هذه المجموعة.
فتح الحزمة
k this deck
34
You use a unary minus sign preceding a value to make the value ____.

A) negative
B) positive
C) valid
D) constant
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 72 في هذه المجموعة.
فتح الحزمة
k this deck
35
When creating a for loop, which statement will correctly initialize more than one variable?

A) for a=1, b=2
B) for(a=1; b=2)
C) for(a=1, b=2)
D) for(a = 1&& b = 2)
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 72 في هذه المجموعة.
فتح الحزمة
k this deck
36
When you want to increase a variable's value by exactly 1, use the ____.

A) power statement
B) accumulating operator
C) binary operators
D) prefix increment operator
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 72 في هذه المجموعة.
فتح الحزمة
k this deck
37
How many times will outputLabel be called? for(customer = 1; customer <= 20; ++customer)
For(color = 1; color <= 3; ++color)
OutputLabel();

A) 0
B) 3
C) 20
D) 60
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 72 في هذه المجموعة.
فتح الحزمة
k this deck
38
A(n) ____________________ is a body with no statements in it.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 72 في هذه المجموعة.
فتح الحزمة
k this deck
39
A for loop provides a convenient way to create a(n) ____ loop.

A) counter-controlled
B) posttest
C) while
D) infinite
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 72 في هذه المجموعة.
فتح الحزمة
k this deck
40
A(n) ____ loop is a special loop that is used when a definite number of loop iterations is required.

A) while
B) for
C) else
D) do…while
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 72 في هذه المجموعة.
فتح الحزمة
k this deck
41
Why would a programmer use curly braces in the body of a do…while loop?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 72 في هذه المجموعة.
فتح الحزمة
k this deck
42
Why would a loop with altered user input be considered a type of indefinite loop? Give an example.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 72 في هذه المجموعة.
فتح الحزمة
k this deck
43
Match each term with the correct statement below.
a.prefix ++
f.loop fusion
b.block
g.decrementing
c.definite loop
h.for loop
d.loop control variable
i.sleep() method
e.binary operators
A shortcut for incrementing and accumulating
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 72 في هذه المجموعة.
فتح الحزمة
k this deck
44
Match each term with the correct statement below.
a.prefix ++
f.loop fusion
b.block
g.decrementing
c.definite loop
h.for loop
d.loop control variable
i.sleep() method
e.binary operators
The value that determines whether loop execution continues
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 72 في هذه المجموعة.
فتح الحزمة
k this deck
45
Describe the purpose of a loop control variable. How are Boolean values and a while loop involved?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 72 في هذه المجموعة.
فتح الحزمة
k this deck
46
Besides initializing, testing, and incrementing, you can also perform other tasks with a for loop. What are some of these tasks? Use code samples as examples.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 72 في هذه المجموعة.
فتح الحزمة
k this deck
47
What would happen if a semicolon is mistakenly placed at the end of a partial statement of a while loop with a Boolean expression and with an empty body?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 72 في هذه المجموعة.
فتح الحزمة
k this deck
48
Match each term with the correct statement below.
a.prefix ++
f.loop fusion
b.block
g.decrementing
c.definite loop
h.for loop
d.loop control variable
i.sleep() method
e.binary operators
Subtracting 1 from a variable
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 72 في هذه المجموعة.
فتح الحزمة
k this deck
49
Match each term with the correct statement below.
a.prefix ++
f.loop fusion
b.block
g.decrementing
c.definite loop
h.for loop
d.loop control variable
i.sleep() method
e.binary operators
Part of the Thread class in the java.lang package
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 72 في هذه المجموعة.
فتح الحزمة
k this deck
50
How does a for loop work?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 72 في هذه المجموعة.
فتح الحزمة
k this deck
51
Match each term with the correct statement below.
a.prefix ++
f.loop fusion
b.block
g.decrementing
c.definite loop
h.for loop
d.loop control variable
i.sleep() method
e.binary operators
Within parentheses are three sections separated by exactly two semicolons
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 72 في هذه المجموعة.
فتح الحزمة
k this deck
52
How are nested loops implemented in a loop structure?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 72 في هذه المجموعة.
فتح الحزمة
k this deck
53
How could a programmer identify and escape from an infinite loop?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 72 في هذه المجموعة.
فتح الحزمة
k this deck
54
Match each term with the correct statement below.
a.prefix ++
f.loop fusion
b.block
g.decrementing
c.definite loop
h.for loop
d.loop control variable
i.sleep() method
e.binary operators
Multiple statements within curly braces
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 72 في هذه المجموعة.
فتح الحزمة
k this deck
55
Match each term with the correct statement below.
a.prefix ++
f.loop fusion
b.block
g.decrementing
c.definite loop
h.for loop
d.loop control variable
i.sleep() method
e.binary operators
The technique of combining two loops into one
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 72 في هذه المجموعة.
فتح الحزمة
k this deck
56
How could you rewrite the following code to have the arithmetic performed only once, even if the loop executes 1,000 times?
while (x < a + b)
// loop body
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 72 في هذه المجموعة.
فتح الحزمة
k this deck
57
Match each term with the correct statement below.
a.prefix ++
f.loop fusion
b.block
g.decrementing
c.definite loop
h.for loop
d.loop control variable
i.sleep() method
e.binary operators
Operate on two values
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 72 في هذه المجموعة.
فتح الحزمة
k this deck
58
What are some of the shortcuts Java provides programmers for incrementing and accumulating? Give examples of statements.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 72 في هذه المجموعة.
فتح الحزمة
k this deck
59
Describe how a loop is controlled by a Boolean expression.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 72 في هذه المجموعة.
فتح الحزمة
k this deck
60
Match each term with the correct statement below.
a.prefix ++
f.loop fusion
b.block
g.decrementing
c.definite loop
h.for loop
d.loop control variable
i.sleep() method
e.binary operators
A counter-controlled loop
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 72 في هذه المجموعة.
فتح الحزمة
k this deck
61
Explain why an infinite loop might not actually execute infinitely.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 72 في هذه المجموعة.
فتح الحزمة
k this deck
62
How are indefinite loops used for validating data? Why is a loop structure typically the better choice for validating data than an if statement?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 72 في هذه المجموعة.
فتح الحزمة
k this deck
63
Write a definite while loop that initializes a loop control variable named decreaseOne to 10 and continues until decreaseOne > 0. Decrement the loop control variable by 1 and include the println output "Keep going" within the loop.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 72 في هذه المجموعة.
فتح الحزمة
k this deck
64
counterLoop = 1;
while(counterLoop < 10);
{
System.out.println("Enter a new value");
counterLoop = counterLoop + 1;
}
What is the problem in the above while loop? How would you correct the problem?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 72 في هذه المجموعة.
فتح الحزمة
k this deck
65
public class CompareValues
{
public static void main(String[] args)
{
int a = 10, b = 10, c = 11;
boolean compare1 = (++b == a);
boolean compare3 = (b++ == c);
System.out.println("Compare 1 value = " + compare1);
System.out.println("Compare 2 value = " + compare2);
}
}
Using the above code, what values will appear in compare1 and compare2 when the println commands execute? Describe how the values of compare1 and compare2 change as the statements are executed.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 72 في هذه المجموعة.
فتح الحزمة
k this deck
66
while(10 > 1)
{
System.out.println("Enter a new value");
}
Identify the problem that exists in the above code.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 72 في هذه المجموعة.
فتح الحزمة
k this deck
67
public class CaseDemo
{
public static void main(String[] args)
{
int myVal, yourVal;
myVal = 10;
System.out.println("My initial value is " + myVal);
yourVal = ++myVal;
System.out.println("My new value is " + myVal);
System.out.println("Your value is " + yourVal):
}
}
Using the above code, describe how the three println output commands will appear. Explain the values stored in the variables during code execution.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 72 في هذه المجموعة.
فتح الحزمة
k this deck
68
Loop control variables can be evaluated at the start or the end of the loop. Describe both pretest loops and posttest loops. How do do…while loops execute?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 72 في هذه المجموعة.
فتح الحزمة
k this deck
69
Describe a counter-controlled loop. Explain the process of incrementing and decrementing, and explain the best method for executing a loop a specific number of times.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 72 في هذه المجموعة.
فتح الحزمة
k this deck
70
Create an indefinite while loop that will validate that the loop control variable named userNum is less than the constant MAXVALUE. While true, create a println statement to output "Please enter a higher value". Once MAXVALUE is reached, create a final println statement that will output "Max value reached".
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 72 في هذه المجموعة.
فتح الحزمة
k this deck
71
public class DoWhileExample
{
public static void main(String[] args)
{
int currentValue;
____
____
____
____
____
}
}
Complete the code above by writing a do…while posttest loop that will output the value of the variable currentValue in a println statement. After the output statement, add a decrement statement to decrease the value of currentValue by 1. Continue the loop until currentValue is equal to 0.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 72 في هذه المجموعة.
فتح الحزمة
k this deck
72
Write a for loop that will initialize the variables value1 to 11 and value2 to 19. Create a test section of the for statement that will test if value1 is greater than 10 and value2 is less than 20. Finally, end the for statement by incrementing value1 by 1. In the loop body, write a println statement that will display the contents of value1.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 72 في هذه المجموعة.
فتح الحزمة
k this deck
locked card icon
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 72 في هذه المجموعة.