Extract particular loop number from a loop

In my code, a loop is occurring 25 times, where the variable has been assigned as part. (example has been provided below)


for (int part = 0; part < 75; part += 3)
{
}

1st loop --> part = 0;
2nd loop --> part = 3;
----
25th loop---

now, my question is how i can extract only 3rd and 6th loop, where part = 6 & 15;

Thank you


Wait, if you only want the stuff at pos 6 and 3, then why do you loop through the entire thing? Why don’t you only do those specific calculations?

But to answer your question, just use an if statement.
if(part == 6 || part == 15)
// code
Hi,

Thank you very much for your quick and good reply.

Well, the whole code is bit complex, but to make the question simple i used such way.

However,
if(part == 6 || part == 15) represents,

if variable part is equal to 6 and 15
or,

if variable part is equal to 6 or 15.

Because i am thinking if(part == 6 && part == 15) in this way.

Again, i am a beginner, so please correct me if i am wrong.

I am hoping for your kind response now.

Thank you

condition1 && condition2 is the same thing as "if cond1 and cond2 are both true"

Vs

cond1 || cond2 is the same thing as "if cond1 or cond2 is true"

if(part == 6 && part == 15) is always going to evaluate to false, because part can’t be 2 different numbers at once.
Topic archived. No new replies allowed.