 One of the things we commonly do in programming is find where an item is within an array. Consider this array of integers. We'd like to find out where the number 15 is in the array. The way we do it by hand is to scan the array from left to right until we find the number, as in this case. Or if we get to the end and we haven't found the number. Let's write the code to do a linear search through a data array, looking for a given value, and returning to position where it was found. We'll run a for loop, starting at the beginning of the array, as long as the position is less than the length of the array, one position at a time. And if the data at the position that we're looking at equals the value we're looking for, we'll return that position. If we get out of the loop without returning anything, that means the value wasn't in the array, and we'll return negative one to indicate an invalid index. Here's our main program. It sets up an array of integers, and then has a do while loop that asks for a number to find, a value. Does a linear search through the data array, and tells where it was found, and prints the result. Let's compile that, and let's run it. We'll look for 15. It's at index 3. Let's look for 78, which isn't in the array, and it gives us back a negative one. When testing a program, you want to test at the boundaries. You want to test to see that it will find the first element in the array, and the last element in the array. And this program works. That's our linear search. Although the program works, my personal preference is to have only one return from a method than having two different places where we return a value. Let's rewrite this method to use only one return. The way we're going to do this is we're going to start our position at zero. As long as there are items left to look at in the data array, and the one that we're currently looking at is not equal to the value, we move on to the next position. Once we exit the loop, we're going to see if the position is less than the length of the array. If so, that's where it was found, otherwise it's not found. And we'll use the ternary operator instead of an if statement. We're going to return if the position is less than data dot length, the position, otherwise negative one. Let's compile that, and let's run it. 15 is found at index 3, 78 isn't in the array, 37 is at the beginning, and 56 is at the end. And this algorithm also works. One thing to note, the time required for this algorithm is proportional to the number of items. If your array has 60 items, then on the average it will take 10 times as long as when the array has only 6 items. In our next video, we'll examine a more efficient search, the binary search.