954,499 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Repeat a segment of a program several

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
}
GeorgeGVD
Newbie Poster
19 posts since Oct 2011
Reputation Points: 10
Solved Threads: 0
 

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

vishwanath.m
Newbie Poster
13 posts since May 2011
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: