Questions tagged [continue]

A language construct typically used to bypass the rest of a loop and return to the beginning for the next iteration.

Using continue will go back to the first line of the loop, in this example when i is 2 or 3 the program will immediately go back to the first line: for i in range(1, 6) before the current iteration has finished

Example (Python):

for i in range(1, 6):
    print(i)
    if i == 2 or i == 3:
        continue
    print("do stuff")
print("after the loop")

Output:

1
do stuff
2
3
4
do stuff
5
do stuff
after the loop

Also see .

724 questions
3
votes
3 answers

Perl programming: continue block

I have just started learning Perl scripting language and have a question. In Perl, what is the logical reason for having continue block work with while and do while loops, but not with for loop?
madCode
  • 3,733
  • 5
  • 26
  • 31
3
votes
2 answers

Does continue statement really increases the speed of the loop in C++?

So, I am new to online competitive programming and i came across a code where i am using the if else statement inside a for loop. I want to increase the speed of the loop and after doing some research i came across break and continue statements. So…
3
votes
2 answers

What Is The Scope Of Continue In A Nested Python For Loop?

When using nested for loops, if I use continue inside the inner nested for loop, does the scope of that continue only apply to the inner loop or will it continue the outer loop? Note: For what I am working on I only want the continue to affect the…
3
votes
4 answers

Continue in a run block in Kotlin

I'm trying to convert the following Java code to Kotlin in an idiomatic way: for (Group group : groups) { String groupName = group.getName(); if (groupName == null) { warn("Group name is null for group " + group.getId()); …
idunnololz
  • 8,058
  • 5
  • 30
  • 46
3
votes
2 answers

php "continue" seemingly not working

I have a script which goes through every filename in a directory and removes unwanted files. Amount other things, it matches filenames in a CSV file and then removes a file in an adjacent cell.
UnluckyForSome9
  • 301
  • 1
  • 9
3
votes
4 answers

Check number not a sum of 2 ints on a list

Given a list of integers, I want to check a second list and remove from the first only those which can not be made from the sum of two numbers from the second. So given a = [3,19,20] and b = [1,2,17], I'd want [3,19]. Seems like a a cinch with two…
Josh Friedlander
  • 10,870
  • 5
  • 35
  • 75
3
votes
6 answers

continue; used to skip many loops

Here is a schema of my code : while (..) { for (...; ...;...) for(...;...;...) if ( ) { ... continue; } } What will do the continue? He will only make the second loop…
Flo
  • 261
  • 1
  • 3
  • 6
3
votes
1 answer

Why is continue placed after yield return?

I stumbled over this piece of code: public IEnumerable Process() { foreach (var item in items) { if (item.Created < DateTime.Now) { yield return item; continue; } } } Can…
CodeNoob
  • 41
  • 1
  • 4
3
votes
2 answers

Detection of Loops in Java Bytecode - Distinguishing back edge types

Background: Before asking my question, I wish to state that I have checked the following links: Identify loops in java byte code goto in Java bytecode http://blog.jamesdbloom.com/JavaCodeToByteCode_PartOne.html I can detect the loops in the…
3
votes
2 answers

When to use break, and continue in C language?

When to use break, and continue in C language? Can I use them both with loop, and without loop? If a condition in a loop is enough to instruct whether to continue or not continue then what are the needs use them? Is it a good practice to use…
Nabila Tajrin
  • 73
  • 1
  • 7
3
votes
4 answers

PHP Is it possible to skip two or more iterations?

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)?
giorgio79
  • 3,787
  • 9
  • 53
  • 85
3
votes
3 answers

PHP - Difference between break and continue in switch case

What is the different between switch (variable) { case 'value': # code... break; case 'value': # code... break; } and this one switch (variable) { case 'value': # code... …
Vinsens
  • 199
  • 6
  • 19
3
votes
3 answers

Why should I use continue as opposed to an empty if statement?

For example: What is the disadvantage/advantage of using this block: for(int i = 0; i < 10; i++) { if(i < 9){} else Console.Writeline(i); } As opposed to this block: for(int i = 0; i < 10; i++) { if(i < 9) { continue; } …
Jaja
  • 51
  • 8
3
votes
1 answer

python skipping a for loop

I'm writing code to find latitudes and longitudes, and calculate a distance within a certain radius of a point, and separate the two files. For the first 5 iterations, the program runs fine, but after that, the program does not run through the inner…
drezap
  • 83
  • 1
  • 1
  • 8
3
votes
3 answers

Using patch color and while loop to command turtle movement in netlogo

I am very new to netlogo so this is probably a very basic question, but I am stuck. I want to use a while loop (so the commands keep occurring throughout the run) and patch color to dictate how the turtle will move. If the turtle is not on a red…
emenyea
  • 31
  • 2