Quiz on Java For Loop
The for loop in Java is a control flow statement that allows you to run a block of code a specific number of times. It is especially useful when the number of iterations is known in advance.
Quiz Summary
0 of 15 Questions completed
Questions:
Information
You have already completed the quiz before. Hence you can not start it again.
Quiz is loading…
You must sign in or sign up to start the quiz.
You must first complete the following:
Results
Results
0 of 15 Questions answered correctly
Your time:
Time has elapsed
You have reached 0 of 0 point(s), (0)
Earned Point(s): 0 of 0, (0)
0 Essay(s) Pending (Possible Point(s): 0)
Categories
- Not categorized 0%
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- Current
- Review / Skip
- Answered
- Correct
- Incorrect
- Question 1 of 15
1. Question
What is the output of:
for (int i = 1; i <= 3; i++) {
System.out.print(i + ” “);
}CorrectIncorrect - Question 2 of 15
2. Question
How many times will this loop execute?.
for (int i = 0; i < 5; i++) {
System.out.print(“*”);
}
CorrectIncorrect - Question 3 of 15
3. Question
Which part of the `for` loop is optional in Java?
CorrectIncorrect - Question 4 of 15
4. Question
What happens if the loop condition is always true and no `break` is used?
CorrectIncorrect - Question 5 of 15
5. Question
What is the output?
for (int i = 0; i < 3; i++) {
if (i == 1) continue;
System.out.print(i);
}CorrectIncorrect - Question 6 of 15
6. Question
Which keyword is used to stop the loop early?
CorrectIncorrect - Question 7 of 15
7. Question
Can a `for` loop be written without the loop body?
CorrectIncorrect - Question 8 of 15
8. Question
Which of these is the correct format for a basic `for` loop?
CorrectIncorrect - Question 9 of 15
9. Question
Can we have nested `for` loops in Java?
CorrectIncorrect - Question 10 of 15
10. Question
What will happen?
for (;;) {
System.out.println(“Hello”);
}CorrectIncorrect - Question 11 of 15
11. Question
What is the output of:
for (int i = 5; i > 0; i–) {
System.out.print(i);
}CorrectIncorrect - Question 12 of 15
12. Question
Which of the following can be used in the update section of a `for` loop?
CorrectIncorrect - Question 13 of 15
13. Question
What is the scope of the variable `i` in:
for (int i = 0; i < 5; i++) {
// body
}
System.out.println(i);CorrectIncorrect - Question 14 of 15
14. Question
What does `i += 2` mean in a `for` loop?
CorrectIncorrect - Question 15 of 15
15. Question
What is the output?
for (int i = 0; i < 5; i += 2) {
System.out.print(i);
}CorrectIncorrect
Summary
This quiz tests your knowledge of `for` loop syntax, control flow, nested loops, infinite loops, and scope handling. Great for coding interviews, Java exams, and practice tests.
