Advertisement

looping

Started by November 30, 2002 05:31 PM
28 comments, last by craphead 21 years, 11 months ago
how do i loop back from the end of my code to a certain spot in my code?
50/50 Robotics and Software
What language?

Before I couldn''t spell engineer, now I are one!
--Before I couldn't spell engineer, now I are one!
Advertisement
Urhm.... how about some specifics? If don''t mind burning in hell after you die, you can use a ''goto'' statement, otherwise, use a loop, like so:

while(loop = true)
{
// code here





} // skips back up to while

I''m guessing you already knew this, and what you''re looking for IS actually a goto. However, I think you''ll find that with good code design, you will never need to do that. Post again with what you are trying to accomplish, and maybe some code snippets. That''ll make it alot easier to help you.

By the way I THINK* the way to use a goto is like this:

line_label:
// code here
goto line_label;

...seeing how I don''t use them though, I''m not sure about that. =)

goto ... but using it is in most cases avoidable and should be avoided coz'' it can be very confusng and causing errors if not used right. its better to break the code into several functions and classes with functions

what language are u using?

another way would be to put while(){
} around your code... or some other loop     
---- sig coming soon
what header file do i use to define loop?
50/50 Robotics and Software
you don''t need any.
Advertisement
it says that loop is undefined
50/50 Robotics and Software
because theres no such thing as ''loop''
i suggest you read some primer tutorials on the net or get a book.

-eldee
;another space monkey;
[ Forced Evolution Studios ]

::evolve::

Do NOT let Dr. Mario touch your genitals. He is not a real doctor!

-eldee;another space monkey;[ Forced Evolution Studios ]
The, probably better, solution, as others have insinuated at is to wrap the code you want to execute more than once into its own function, then call that function as many times you want.

As foor "loop undefined", I guess you tried Beowulf_ as it was. loop is a bool type variable (which of course must be defined) which is tested to see if the block shall be executed or not. If you don't want the block to be skipped, you need to set it to true before the loop. You would also need a way to set it to false to exit the loop.

EDIT: Btw, I think someone needs to take a trip to the book store (hint, hint)



[edited by - CWizard on November 30, 2002 7:23:49 PM]
i use c++
50/50 Robotics and Software

This topic is closed to new replies.

Advertisement