1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Lena [83]
3 years ago
6

In reference to for-each loops, which of the following statements is true? f

Computers and Technology
2 answers:
Lina20 [59]3 years ago
7 0

Answer:

Option B: an index variable is NOT explicitly coded

Explanation:

For-each loops appear in some programming languages such as Java and JavaScript. It is sometimes considered as an enhanced version of for loop to traverse elements in an array.

To traverse the elements of an array using the For-Each loop, index variable is not required. The syntax of For-Each loop in Java is as follows:

<em>for(type  variableName : arrayName)</em>

<em>{</em>

<em>    // some codes</em>

<em>}</em>

One sample code to traverse array using For-each loop is as follows:

  1. int myArray[] = {3, 5, 7, 9, 11};
  2. for(int num: myArray)
  3. {
  4.    System.out.println(num);
  5. }

The Java codes above will output 3 5 7 9 11. In every round of the iteration of the For-each loop, the loop variable <em>num</em> will just take one value of element in the array and print it out one after another.

Artemon [7]3 years ago
4 0

In computer programming, the for each loop is called enhanced for each loop.

It is the shorter version of the traditional for loop used in computer programming.

The enhanced for loop is written as shown.

For ( data type variable : array_name )

{

code of the loop goes here

}

An example of integer array using enhanced for loop is shown below. The Java code is given below.

1. First, an integer array is declared and initialized simultaneously. Hence, the size of the array is not known explicitly and no index variable is needed.

2. Next, an integer variable is initialized which iterates over every element of the array.

3. The variable which holds the element of the array is displayed.

int[] tens = { 10, 20, 30, 40, 50, 60, 70, 80, 90 } ;

for ( int t : tens )

{

System.out.println( t );

}  

a.  The above code does not include any index variable. The enhanced loop can only be used to traverse the given array.

The array can only be traversed in forward direction, i.e., elements of the array can only be traversed beginning from the first element to the last.

By default, enhanced for loop traversal begins from index 0 of the array to the last index of the array. This needs the index variable to be coded.

Also, index variable gives traditional for loop more control on how the elements can be traversed and which elements to be traversed.

b.  The for each loop can not always be re written as for loop. The for loop is used when more just element traversal is needed.

c.  The for each loop executes only till the variable traverses through all the elements of the array. The loop terminates when all the elements are visited.  Thus, ArrayIndexOutOfBoundsException can not be thrown by the enhanced for loop.

You might be interested in
In this problem, we explore some of the properties of the CRC. For the generator G (=1001) given in Section 5.2.3, answer the fo
allochka39001 [22]

Answer:

b

Explanation:

5 0
3 years ago
Which is a benefit of owning a desktop computer instead of a laptop?
Setler79 [48]
B) a desktop is less likely to be stolen or damaged
4 0
3 years ago
Read 2 more answers
One way to save time and get to the colleges that you are most interested in at a college fair is to
son4ous [18]

Answer:

Identify the location of the college stand in advance.

Explanation:

One way to save time and get to the colleges that you are most interested in at a college fair is to find out in advance the information about the fair, the colleges that are participating and from that pick the more interesting ones and identify the location of their stands. Like that when you arrive to the fair you can go directly to them and find them easily which will save you a lot of time as you won't be walking around the whole place to find them.

8 0
3 years ago
Read 2 more answers
This is Tim’s first job. He is not familiar with how the Internet is used at the workplace. Match the applications of Internet u
Gala2k [10]

Answer:

A - 2

B - 3

C - 5

D - 4

E - 1

Explanation:

A. Virtual private network : 2

This is very useful when you have to work from home or visiting a client and need access to files/applications just like if you were at the office.

B. Email :  3

Yes, this is basically why the Internet was created in the first place.

C. Social networking sites : 5

Social networks are indeed a great marketing tool, allowing to target potential customers very precisely.

D. Search engines :  4

Yes, to find information about new products for the company, how the competitors are doing and so on.

E. Video and web conferencing:  1

Another great tool for employees working from home for example, or for employees located in an office at the other side of the country.

4 0
3 years ago
What is the LER for a rectangular wing with a span of 0.225m and a chord of 0.045m
ch4aika [34]

Calculate LER for a rectangular wing with a span of 0.225m and a chord of 0.045m. The weight of the glider is 0.0500 Newtons. (Note: the wing span is the width of the wing and is measured from wing tip to wing tip, or perpendicular to the fuselage. The wing chord is the length of the wing measured parallel or along the length of the fuselage.)

Answer:

Area of rectangular wing = span × chord = 0.225×0.045= 0.010125m2

LER = Area/weight = 0.010125/0.0500 = 0.2025

4 0
3 years ago
Other questions:
  • Explain what the 35ppm specification means
    13·1 answer
  • What are the advantages and disadvantages to a home user of replacing dial-up Internet access with broadband?
    15·1 answer
  • A network host with an IP address of 192.168.10.200 wants to send a message to a destination computer with an assigned IP addres
    6·1 answer
  • What is a seismogram?
    9·1 answer
  • You can send messages that include photos and videos between mobile devices using ________ technology.
    12·1 answer
  • Which of the following is the correct order of the SDLC?
    14·1 answer
  • What is the purpose of application software policies?
    12·1 answer
  • WRITE A JAVA PROGRAM TO PRINT THE PATTERN<br> 13579<br> 2468<br> 357<br> 46<br> 5
    12·1 answer
  • Create a list with 5 numbers and find the smallest and largest number in the list and also the sum and product of the numbers in
    9·1 answer
  • Write the definition of a function that evaluates three double numbers and returns true if the floor of the product of the first
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!