I'm trying to make a loop that that will skip a number but has a certain limit to how high it goes...

For example:

I have a for loop:

for (i = 0; i < count;  i++ )

but lets say I want to skip a number in that loop.

Like if count was 10. The loop will display all things from 0 to 10. What if I want it to skip like when i =5?

Recommended Answers

All 5 Replies

Use the continue keyword. It skips to the next iteration.

for (i = 0; i < count;  i++ )
        if ( i == 5 )


Can you look at my other thread on here, the one about help on structors.

This problem pertains to that. I tried doing an if statement to just print "ok" when it comes accross the invalid number. The invalid variable must not have a value or something, cause my if statment is

if(i != invalid)

but it always prints prints ok, even though the way I have my data file set up is that the invalid data is on line three, it even prints it in the validate function, but nothing happens later in the other function.

I figured it out.

was it the "return invalid" statement being in the wrong place?

Yeah, I had return (invalid) at the end of the function, which meant it would return invalid after the whole loop had done, so it would always return invalid as 5. I moved it to be in the if statement, that way it actually returns the number of the line where the error is.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.