Lecture: Introduction to JAVA Loops Flashcards
2nd part of 1st Sem
What is the primary purpose of loops in programming?
To execute a set of instructions repeatedly
Which of the following is NOT a type of loop in Java?
Until loop
What is the syntax for a while loop in Java?
while (condition) { statements; }
What will happen if the condition in a while loop is always true?
The loop will run indefinitely
What is a common pitfall when using loops?
Infinite loops
What does the increment/decrement part of a for loop do?
It updates the loop variable for the next iteration
What will the following code snippet output?
int i = 0;
while (i <5) {
System.out.println(i);
i++;
}
0 1 2 3 4
What are the components of a WHILE loop in Java?
Test and Update Expression
When will the TEST EXPRESSION in a WHILE loop be evaluated?
Before each iteration
What is the purpose of the UPDATE EXPRESSION in a WHILE loop?
increments or decrements the loop variable by some value