212k views
17 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 Sponce
by
5.2k points

1 Answer

2 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 Croote
by
4.2k points