Member Avatar for mehnihma

Can you help me how to convert this for loop to Enhanced For-Loop?

Thanks

for (int x = 0; x < grade.length; ++x)

		if (grade[x]==grade1)
		
		{
		
		gradesum = score [x] * testscore1;
		
		}

since in an enhanced for loop, you won't automatically have the x which you use as index for score and which, I assume, link the element in score to the element in grade, what do you want it for?

Do you know for sure that it's possible and/or sensible to convert it? At first sight I can't see a sensible way to do it, and I would keep the loop you've currently got.

You would first need to convert your parallel array structure to a map or a single array of objects that contain both values.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.