Deck 6: Looping
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
Match between columns
سؤال
سؤال
Match between columns
سؤال
Match between columns
سؤال
Match between columns
سؤال
Match between columns
سؤال
سؤال
سؤال
Match between columns
سؤال
Match between columns
سؤال
Match between columns
سؤال
Match between columns
سؤال
Match between columns
سؤال
سؤال
Match between columns
سؤال
Match between columns
سؤال
Match between columns
سؤال
سؤال
Match between columns
سؤال
Match between columns
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
فتح الحزمة
قم بالتسجيل لفتح البطاقات في هذه المجموعة!
Unlock Deck
Unlock Deck
1/77
العب
ملء الشاشة (f)
Deck 6: Looping
1
It is important that the loop control ____ be altered within the body of the loop.
A) value
B) variable
C) constant
D) argument
A) value
B) variable
C) constant
D) argument
B
2
Before entering a loop, the first input statement, or ____, is retrieved.
A) empty body
B) posttest loop
C) loop body
D) priming read
A) empty body
B) posttest loop
C) loop body
D) priming read
D
3
A counted loop is the same as an indefinite loop.
False
4
Many seasoned programmers start counter values at 1 because they are used to doing so when working with arrays.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
5
Making a comparison to 0 is slower than making a comparison to any other value.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
6
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) empty
B) while
C) definite
D) control
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
7
Programmers rarely use indefinite loops when validating input data.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
8
When nesting loops, the variable in the outer loop changes more frequently.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
9
A(n) ____ is a kind of indefinite loop.
A) counter-controlled
B) event-controlled
C) initialized
D) validating
A) counter-controlled
B) event-controlled
C) initialized
D) validating
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
10
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
11
On many keyboards, the Break key is also the ____ key.
A) Pause
B) Esc
C) Delete
D) Ctrl
A) Pause
B) Esc
C) Delete
D) Ctrl
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
12
You can initialize one or more variables in the first section of a for statement.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
13
The statements that make up a loop body will continue to execute as long as the expression value remains false.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
14
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;
}
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;
}
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
16
A ____ is a structure that allows repeated execution of a block of statements.
A) body
B) Boolean expression
C) loop
D) loop control
A) body
B) Boolean expression
C) loop
D) loop control
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
17
A loop controlled by the user is a type of ____ loop.
A) indefinite
B) definite
C) counter-controlled
D) incrementing
A) indefinite
B) definite
C) counter-controlled
D) incrementing
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
18
____ is the process of ensuring that a value falls within a specified range.
A) Value checking
B) Data integrity
C) Validating data
D) Syntax checking
A) Value checking
B) Data integrity
C) Validating data
D) Syntax checking
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
19
A loop that never ends is called a(n) ____ loop.
A) definite
B) infinite
C) while
D) for
A) definite
B) infinite
C) while
D) for
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
20
Shortcut operators are a programmer's only choice when incrementing or accumulating a variable's value.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
21
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
A) while
B) for
C) else
D) do…while
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
22
What is wrong with the following code? x=1;
While (x<5);
{ System.out.println (x);
x++;
}
A) Syntax error in the println method
B) Incorrect use of prefix increment operator
C) Semicolon at the end of the while expression
D) Incorrect initialization
While (x<5);
{ System.out.println (x);
x++;
}
A) Syntax error in the println method
B) Incorrect use of prefix increment operator
C) Semicolon at the end of the while expression
D) Incorrect initialization
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
23
The ____ loop is the posttest loop used in Java.
A) for
B) counter-controlled
C) while
D) do...while
A) for
B) counter-controlled
C) while
D) do...while
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
24
Assume d and x are integers: d = 5;
X = 2 * ++d;
What is the value of x ?
A) 10
B) 11
C) 12
D) 13
X = 2 * ++d;
What is the value of x ?
A) 10
B) 11
C) 12
D) 13
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
25
With ____ loops, the order of the conditional expressions can be important.
A) nested
B) posttest
C) pretest
D) indefinite
A) nested
B) posttest
C) pretest
D) indefinite
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
26
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)
A) for a=1, b=2
B) for(a=1; b=2)
C) for(a=1, b=2)
D) for(a = 1&& b = 2)
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
27
A(n) ____ loop is one that performs no actions other than looping.
A) nested
B) do-nothing
C) indefinite
D) posttest
A) nested
B) do-nothing
C) indefinite
D) posttest
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
28
One execution of any loop is called a(n) ____.
A) run
B) loop
C) prime
D) iteration
A) run
B) loop
C) prime
D) iteration
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
29
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
A) while
B) do…while
C) for
D) else
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
30
____ 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
A) Loop fusion
B) Prefix incrementing
C) Short-circuit evaluation
D) Do-nothing looping
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
31
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
A) power statement
B) accumulating operator
C) binary operators
D) prefix increment operator
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
32
In the expressions b = 8 and c = --b , what value will be assigned to the variable c ?
A) 7
B) 8
C) 9
D) 10
A) 7
B) 8
C) 9
D) 10
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
33
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
A) semicolon
B) equal sign
C) period
D) comma
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
34
A for loop provides a convenient way to create a(n) ____ loop.
A) counter-controlled
B) posttest
C) while
D) infinite
A) counter-controlled
B) posttest
C) while
D) infinite
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
35
A(n) ____ is a body with no statements in it.
A) infinite loop
B) empty body
C) finite loop
D) event-controlled loop
A) infinite loop
B) empty body
C) finite loop
D) event-controlled loop
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
36
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
A) the loop control variable is true
B) the loop control variable is false
C) the user types EXIT
D) the program terminates
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
37
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
A) ++score
B) score++
C) ++score = score + 1
D) score = score + 1
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
38
You use a unary minus sign preceding a value to make the value ____.
A) negative
B) positive
C) valid
D) constant
A) negative
B) positive
C) valid
D) constant
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
39
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
for(color = 1; color <= 3; ++color)
outputLabel();
A) 0
B) 3
C) 20
D) 60
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
40
The process of repeatedly increasing a value by some amount is known as ____.
A) checking
B) adding
C) accumulating
D) containing
A) checking
B) adding
C) accumulating
D) containing
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
41
Match between columns
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
42
What is wrong with the following code? while (4>2)
System.out.println ("Hi there");
A) missing curly braces
B) illegal conditional expression
C) infinite loop
D) Syntax error in the output statement
System.out.println ("Hi there");
A) missing curly braces
B) illegal conditional expression
C) infinite loop
D) Syntax error in the output statement
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
43
Match between columns
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
44
Match between columns
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
45
Match between columns
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
46
Match between columns
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
47
What is the output of the following code: loopCount = 1;
While(loopCount < 3)
{
System.out.println("Hello");
loopCount = loopCount + 1;
}
A) Hello
B) Hello Hello
C) Hello Hello
Hello
D) HelloHello
While(loopCount < 3)
{
System.out.println("Hello");
loopCount = loopCount + 1;
}
A) Hello
B) Hello Hello
C) Hello Hello
Hello
D) HelloHello
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
48
What is the output of the following code: for (loop = 1; loop <3; ++loop)
System.out.print(1);
for (loop2 = 1; loop2< 3; ++loop2)
System.out.print(2);
A) 112222
B) 1232212322
C) 122122
D) 122212221222
System.out.print(1);
for (loop2 = 1; loop2< 3; ++loop2)
System.out.print(2);
A) 112222
B) 1232212322
C) 122122
D) 122212221222
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
49
Match between columns
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
50
Match between columns
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
51
Match between columns
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
52
Match between columns
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
53
Match between columns
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
54
What is the output of the following code: loopCount = 1;
While(loopCount < 3)
System.out.println("Hello");
loopCount = loopCount + 1;
A) No output
B) Hello Hello
C) Hello Hello
Hello
D) This is an infinite loop
While(loopCount < 3)
System.out.println("Hello");
loopCount = loopCount + 1;
A) No output
B) Hello Hello
C) Hello Hello
Hello
D) This is an infinite loop
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
55
Match between columns
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
56
Match between columns
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
57
Match between columns
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
58
What kind of loop is this: response = keyboard.nextInt();
While (response == 1)
{
System.out.print ("Enter 1 to continue; 0 to stop");
response = keyboard.nextInt();
}
A) posttest
B) definite
C) event-driven
D) counted
While (response == 1)
{
System.out.print ("Enter 1 to continue; 0 to stop");
response = keyboard.nextInt();
}
A) posttest
B) definite
C) event-driven
D) counted
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
59
Match between columns
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
60
Match between columns
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
61
Why would a loop with altered user input be considered a type of indefinite loop? Give an example.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
62
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?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
63
Explain why an infinite loop might not actually execute infinitely.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
64
How could a programmer identify and escape from an infinite loop?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
65
while(count < getNumberOfEmployees())
Examine the statement above. Write the code that will result in more efficient program execution assuming the result of getNumberOfEmployees() stays the same.
while(count < getNumberOfEmployees())
Examine the statement above. Write the code that will result in more efficient program execution assuming the result of getNumberOfEmployees() stays the same.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
66
How are indefinite loops used for validating data? Why is a loop structure typically the better choice for validating data than an if statement?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
67
How does a for loop work?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
68
Describe how a loop is controlled by a Boolean expression.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
69
Provide a code example of a pretest loop and an example of a posttest loop.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
70
What are some unconventional uses of the three sections inside the parentheses of a for loop? Show at least three examples using code.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
71
What is loop fusion? Write a code segment that uses loop fusion to call two methods, method1 and method2 , 10 times each.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
72
counterLoop = 1;
while(counterLoop < 10);
{
System.out.println("Hello");
counterLoop = counterLoop + 1;
}
What is the problem in the above while loop? How would you correct the problem?
while(counterLoop < 10);
{
System.out.println("Hello");
counterLoop = counterLoop + 1;
}
What is the problem in the above while loop? How would you correct the problem?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
73
public class IncrDemo
{
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.
{
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
74
How are nested loops implemented in a loop structure?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
75
while(10 > 1)
{
System.out.println("This prints forever.");
}
Identify the problem that exists in the above while loop.
{
System.out.println("This prints forever.");
}
Identify the problem that exists in the above while loop.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
76
What are the three sections inside the parentheses of a for loop typically used for?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck
77
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
while (x < a + b)
// loop body
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 77 في هذه المجموعة.
فتح الحزمة
k this deck