PHP Is it possible to skip two or more iterations? Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of PHP Is it possible to skip two or more iterations? without wasting too much if your time.

The question is published on by Tutorial Guruji team.

I am aware we can skip the next iteration with continue in a for loop. Anyway to skip the next x loops (2 or more)?

Answer

You actually can’t, you can do a dirty trick like

for ($i=0; $i<99; $i++){
    if(someCondition) {
        $i = $i + N; // This will sum N+1 because of the $i++ in the for iterator (that fire when the new loop starts)
        continue;
    }
}
We are here to answer your question about PHP Is it possible to skip two or more iterations? - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji