I've this code. I need to do several experiments to obtain de average time it takes to do some methods. Instead of re-running and re-running the program, I want to put a segment of the code in a FOR bucle.

The problem is that my program never ends,it stays looping forever
Here is part of my code

int a= 0;

	for (a= 0; a= 20; a++){    // I WANT IT TO REPEAT FROM HERE (20 times)

	std::clock_t start;  
	double duration;

	// Populates the vector
	for(i=0; i<n; i++) v[i] = i;

	/*
        // Original vector
	cout << "Current Contents:\n";
	for(i=0; i<v.size(); i++) cout << v[i] << " ";
	cout << "\n\n";
        */
	//REARRANGE THE VECTOR
	random_shuffle( v.begin(), v.end());

        start = std::clock(); //Initiate de CLOCK
        rank_sort(v,n,v2); rearrange2(v,n,v2);[/CODE
        duration = (std::clock() - start) / (double) CLOCKS_PER_SEC;   

        std::cout<< <<duration<<endl;

   } // IT REPEATS UNTIL HERE
}

IN your for loop condition you gave a=20 while will always be true so it is in infinite loop...just change it to a<-20

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.