Continue statement to skip 1 part of a loop?

I have a loop that keeps adding 1 to a number.

Then it asks the user whether it wants to skip 5 or not, if they say YES I want it to go 1 2 3 4 6 7 8 -- >

So I said something like:

1
2
3
4
5
int number
char yesorno

if ( yesorno == 'Y' && yesorno=='y' && number=5 )
continue;

is that how it's suppose to be used? I just want it to skip one loop and go to the next number. But it freezes up the program after the user enters Y ( for yes).



Last edited on
Your sample code contains no user prompt or loop. You haven't provided enough info to answer your question.
First create your variable's.
char yesorno;<--- notice semicolon
int NumberToCountTo;<--- used this long name for readability

Then you could prompt for user input
cout << "Do you want to skip number 5?";
cin >> yesorno;

Then create your loop.
for(int LoopIterator = 0;LoopIterator <= NumberToCountTo;LoopIterator++)
{
while (LoopIterator !== 5)
{
cout << "LoopIterator\n";<--- Use this if you want the number's on new line each.
cout << "LoopIterator" << " ";<--- Or this if all on same line with space's.
}
}

That should work, I didn't test it but it should. Post back and let me know if it worked, or if you got any question's.
Well , I think the issue is "number=5" should be "number==5". "number=5" cause number is 5 all the time. so always contine.
if ( yesorno == 'Y' && yesorno=='y' && number=5 )

yesorno can not be 'Y' and 'y' at the same time. I suppose you either mean "if ( yesorno != 'Y' && ...)" or you mean "if ( yesorno == 'Y' || yesorno == 'y' ...)"

Ciao, Imi.
PS: What bolo809 said is still true. "number=5" is also most probably not what you want too. number=5 sets number to 5 and does no checking.

Last edited on
Ok thanks a lot I got it working.
Topic archived. No new replies allowed.