I'm new to C++, and I'm trying to write some code.
I have written this loop:
1 2 3 4 5 6 7 8 9 10 11 12
for (i=1 ,j=1; i<10 ; i++)
{
if (A[i] != A[i-j])
cout << A[i] << " ";
else
j++;
if (i==j)
{
break;
}
}
I need to replace "break" with a command that goes back to main for loop (doing i++). I've tried using goto but it's not a solution since the loop will start all over again. I've tried using ";" but it doesn't help.
What am I doing wrong? Is there a command like that?
There is only one for loop. If you want it to keep looping, just don't break. You're not making much sense. What does the code above do that you don't like?
I don't want it to break. The break is there just to show where I want to put a command.
I want to do this : if (i==j) do i++ and continue the loop which means back to line 1.
for (i=1 ,j=1; i<10 ; i++)
{
if (A[i] != A[i-j])
cout << A[i] << " ";
else
j++;
// at this point, if i==j, do nothing, just roll around to the next loop iteration
if (i != j)
{
// all the other stuff you want to do if i != j
// it will all be skipped over if i==j
}
}
The user can input 10 numbers and the program will show the numbers by order they were input w/o duplications.
I've stated the numbers for debugging :)