Explain how to use a for loop to search an array for an exact match.

What will be an ideal response?

One way to determine whether a given value equals a value in an array is to use a for statement to loop through an array and set a Boolean variable to true when a match is found.
For example, initialize the array valid values and a Boolean variable, isValidItem, using the following statements:
int[] validValues = {101, 108, 201, 213, 266, 304, 311, 409, 411, 412};
bool isValidItem = false;
Next, you can use a for statement to loop through the array and set the Boolean variable to true when a match is found:
for(int x = 0; x < validValues.Length; ++x)
if(itemOrdered == validValues[x])
isValidItem = true;

Computer Science & Information Technology

You might also like to view...

Which of the following statements should be used in secure C programming to display the string "Welcome" not followed by a new-line character?

(a) printf( "Welcome" ); (b) puts( "Welcome" ); (c) printf( "%s", "Welcome" ); (d) None of the above.

Computer Science & Information Technology

. One of the best ways to learn the user-centered development methodology is to develop a web site for an organization or for a person other than yourself. There are many places where you can find a “client” – many on-campus organizations would like to have a site that publicizes their activities. There are also many nonprofit organizations such as service organizations, theatre troupes, and religious groups that would like to set up web pages but don’t have the skills or resources to do so. Another possibility might be a city department such as a parks district who might be interested. When you find a client who is interested, ask them what they envision for their web site. If the conversation elicits a large wish list, feel free to ask them which issues are most important to them.

What will be an ideal response?

Computer Science & Information Technology