Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 15 Online
OpenStudy (anonymous):

When running a for loop is there any way to make it restart the function. Kind of like a return command.

OpenStudy (anonymous):

I meant to say restart the loop. Here is the code I need it for i need it to stop because i only need one solution for each. http://pastebin.com/vA7HeUMi. It is giving me multiple solutions for each. By the way this is Pset2 problem 3

OpenStudy (anonymous):

Looks like your pastebin got deleted. Try using dpaste.com as it keeps stuff longer, and doesn't have the annoying ads.

OpenStudy (anonymous):

you can try making it recalling the function with a base case and return after that example void main() { for(int i = 0; ;i ++) { printf("waha"); if(i == 10) { main(); return; } } }

OpenStudy (anonymous):

ok i used dpaste this time. http://dpaste.com/hold/525841/ . I actually deleted the last post on purpose though because it had an infinite loop that i didn't notice. Now I just need it to only give me one answer for each instead of every possible solution. After that I will put a counter in to Keep track of how many in a row it gets.

OpenStudy (anonymous):

'continue' should help

OpenStudy (anonymous):

I finished my code already what i did is made two separate functions and called one function within another that way I could use return. Have we learned the continue function in this course yet and what does it do?

OpenStudy (anonymous):

I'm not really sure about the course, but the continue sends the flow of control to the first line of the loop from anywhere within the loop.

OpenStudy (anonymous):

o ok what if your using loops within loops which will it return to?

OpenStudy (anonymous):

to the inner one

OpenStudy (anonymous):

o then that wouldn't have worked but thanks. continue may come in handy later tho.

OpenStudy (anonymous):

In your case I guess you could use a flag mechanism with a break or something like that, as per your requirement.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!