1/18
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
What is a loop in programming?
A structure that repeats a set of instructions until a condition is met.
Name the main types of loops in Java.
while
, do...while
, for
, for-each
, and recursion (repetitive behaviour, not a true loop).
Which loop is considered the "monarch" of loops?
while
loop — all other loops can be built from it.
What happens if a while
loop has no terminating condition?
It becomes an infinite loop, causing the program to hang or crash.
When is the condition checked in a do...while
loop?
At the end of the loop, after the body executes.
What does "once or more" mean in a do...while
loop?
The loop runs at least once, even if the condition is false initially.
What is the main advantage of a for
loop over a while
loop?
It’s more concise when the number of iterations is known in advance.
What is the scope of the loop counter in a for
loop?
It’s local to the loop body — cannot be used outside the loop.
What keyword is used to declare an array in Java?
new
, as in new int[10]
.
What is the syntax to declare an integer array of length 10?
int[] numberStore = new int[10];
What type of values can an array hold?
Primitives or objects, depending on how it's declared.
What error is thrown if an invalid array index is accessed?
ArrayIndexOutOfBoundsException
.
How can you avoid going out of bounds in an array?
Use a for
loop with the condition i < array.length
.
What does the “for each” loop simplify?
Iterating through all elements in an array or collection.
What is the syntax of a for each
loop?
for (dataType element : array) { // code }
Can you modify array elements using a for each
loop?
No — it provides read-only access to the values.
What limitation does the for each
loop have compared to for
?
You can't access the index of the current element directly.
Why do arrays use special syntax in Java?
Because they are objects but don’t use constructors directly.
What is a real-world analogy for arrays in Java?
If a variable is a cup, an array is a shelf of cups.