136,634 views
41 votes
41 votes
When is a for loop used in a Java Program?

A. When you already know how many times to perform an action.
B. When you want to test how many times to perform an action.
C. When you don't know how many times to perform an action.
D. When you want to define the name of an action.

User Mikaela
by
3.1k points

1 Answer

19 votes
19 votes

Answer:

A

Step-by-step explanation

Use "for loop" when size/length is pre-defined/know, such as

int[] numbers = new int[]{ 1,2,3,4,5,6,7,8,9,10 };

length : 10

snippet:

numbers.forEach(int num in numbers){

}

// or

for(int i=0; i < numbers.length ; i++){

}

User Rajil TL
by
3.3k points