void function versus value return function

What happens if the return statement is commented out?
Nothing happens when i removed the return statement in void findNumber function.
Can anyone expalin to me what is difference when putting return statement in void function. With return and without it. I didnt see the differences.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;

const int MAXINDEX = 10000;
int list[MAXINDEX];

void generateNumbers() {
	srand((unsigned)time(0));	// seed the random generator
	for (int i=0; i < MAXINDEX; i++)
		list[i] = (rand() % 100)+1;	// generate a random number 
}

void findNumber(int numToFind) {
	for (int i=0; i < MAXINDEX; i++) {
		cout << "Searching...index: " << i << endl;
		if (list[i] == numToFind) {
			cout << "Found number!" << endl;
			return;
		}
	}
}

int main() {
	int number;
	generateNumbers();
	do {
		cout << "Enter number to be searched: ";
		cin >> number;
		findNumber(number);
	} while (true);

	system("PAUSE");	
	return 0;
}Put the code you need help with here.
Using the return statement in a void function is only useful if you want the function to end before the end of the function is reached. In the findNumber function, if you remove the return, it will keep searching the list until it has searched all 10000 elements even if the number was found earlier.
Thank you Peter87. I understood now.
Topic archived. No new replies allowed.