Lecture: Introduction to JAVA Loops Flashcards

2nd part of 1st Sem

1
Q

What is the primary purpose of loops in programming?

A

To execute a set of instructions repeatedly

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

Which of the following is NOT a type of loop in Java?

A

Until loop

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

What is the syntax for a while loop in Java?

A

while (condition) { statements; }

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

What will happen if the condition in a while loop is always true?

A

The loop will run indefinitely

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

What is a common pitfall when using loops?

A

Infinite loops

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

What does the increment/decrement part of a for loop do?

A

It updates the loop variable for the next iteration

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

What will the following code snippet output?

int i = 0;
while (i <5) {
System.out.println(i);
i++;
}

A

0 1 2 3 4

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

What are the components of a WHILE loop in Java?

A

Test and Update Expression

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

When will the TEST EXPRESSION in a WHILE loop be evaluated?

A

Before each iteration

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

What is the purpose of the UPDATE EXPRESSION in a WHILE loop?

A

increments or decrements the loop variable by some value

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