Loops and Arrays

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/18

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

19 Terms

1
New cards

What is a loop in programming?

A structure that repeats a set of instructions until a condition is met.

2
New cards

Name the main types of loops in Java.

while, do...while, for, for-each, and recursion (repetitive behaviour, not a true loop).

3
New cards

Which loop is considered the "monarch" of loops?

while loop — all other loops can be built from it.

4
New cards

What happens if a while loop has no terminating condition?

It becomes an infinite loop, causing the program to hang or crash.

5
New cards

When is the condition checked in a do...while loop?

At the end of the loop, after the body executes.

6
New cards

What does "once or more" mean in a do...while loop?

The loop runs at least once, even if the condition is false initially.

7
New cards

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.

8
New cards

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.

9
New cards

What keyword is used to declare an array in Java?

new, as in new int[10].

10
New cards

What is the syntax to declare an integer array of length 10?

int[] numberStore = new int[10];

11
New cards

What type of values can an array hold?

Primitives or objects, depending on how it's declared.

12
New cards

What error is thrown if an invalid array index is accessed?

ArrayIndexOutOfBoundsException.

13
New cards

How can you avoid going out of bounds in an array?

Use a for loop with the condition i < array.length.

14
New cards

What does the “for each” loop simplify?

Iterating through all elements in an array or collection.

15
New cards

What is the syntax of a for each loop?

for (dataType element : array) { // code }

16
New cards

Can you modify array elements using a for each loop?

No — it provides read-only access to the values.

17
New cards

What limitation does the for each loop have compared to for?

You can't access the index of the current element directly.

18
New cards

Why do arrays use special syntax in Java?

Because they are objects but don’t use constructors directly.

19
New cards

What is a real-world analogy for arrays in Java?

If a variable is a cup, an array is a shelf of cups.