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
7
votes
4 answers

Continue execution on Exception

Below is the script I want to execute. The issue here is once an exception occurs it stops executing, I used continue in the catch block but that did not work. How do I get it working even after an exception occurs it should loop in foreach. I also…
Ishan
  • 4,008
  • 32
  • 90
  • 153
6
votes
4 answers

C# Foreach Loop - Continue Issue

I have a problem with a continue statement in my C# Foreach loop. I want it to check if there is a blank cell in the datagridview, and if so, then skip printing the value out and carry on to check the next cell. Help appreciated greatly. Here is the…
Goober
  • 13,146
  • 50
  • 126
  • 195
6
votes
5 answers

Several nested 'for' loops, continue to next iteration of outer loop if condition inside inner loop is true

I know it is terribly inefficient and ugly code, but if I have three for loops, nested inside each other such as so: for x in range(0, 10): for y in range(x+1, 11): for z in range(y+1, 11): if ... I want to break the two inner…
KOB
  • 4,084
  • 9
  • 44
  • 88
6
votes
4 answers

Why should I avoid using Java Label Statements?

Everywhere across the internet people say that you should avoid using label statements in java. However, I find them very useful in some cases, namely nested loops. I cannot find satisfactory answers as to why not to use them. I think that…
user230331
5
votes
3 answers

Check if Array element is not null in one line C#

I got a neighbor array (consisting of Tile objects), that always has the length of 4, regardless if all elements are filled or not. I want to scan through that array and change the color of a PB contained in the Tile if that element / position is…
Sander Koldenhof
  • 1,223
  • 4
  • 13
  • 26
5
votes
1 answer

Java stops at thread's try-catch

I'm trying to write a code that will return my raspberry's IP when it's on the same network as my computer. The idea is for it to make a broadcast like Samba (Broadcast resolution is the closest to the original NetBIOS mechanism. Basically, a client…
Laura Martins
  • 583
  • 2
  • 6
  • 15
5
votes
2 answers

Python Exception Handling -- Return to Line, Continue

I do a lot of Project Euler coding problems, and Python is my go-to language. A lot of programs typically take forever to complete, so I'm working on implementing something that'll help give diagnostic info on the state of the program: when a…
user4728253
5
votes
3 answers

Is continue instant?

In the follow two code snippets, is there actually any different according to the speed of compiling or running? for (int i = 0; i < 50; i++) { if (i % 3 == 0) continue; printf("Yay"); } and for (int i = 0; i < 50; i++) { if (i…
Joel
  • 1,580
  • 4
  • 20
  • 33
5
votes
4 answers

Conditionals in Elisp's cl-loop facility

I'm trying to wrap my head around Elisp's cl-loop facility but can't seem to find a way to skip elements. Here's an artificial example to illustrate the problem: I'd like to loop over a list of integers and get a new list in which all odd integers…
tmalsburg
  • 354
  • 2
  • 11
5
votes
2 answers

Why is this else: pass needed for processing to continue?

Can someone explain why the else: pass shown below is needed in order for the rest of the code (the final print 'processing... statement) to be executed? Note the print in the else was put there just so I could tell that execution was indeed taking…
martineau
  • 119,623
  • 25
  • 170
  • 301
5
votes
1 answer

Do not continue Javascript for-loop until specified

I need to pause a for loop and not continue until I specify. For each item in the array that I'm looping through, I run some code that runs an operation on a separate device, and I need to wait until that operation is finished before looping to the…
addMitt
  • 951
  • 2
  • 13
  • 27
4
votes
1 answer

Understanding a Julia statement comprising == && increment and continue

I am trying to translate some Julia routine into C (C#, C++). I fail to understand the particular line n == n0 && (n+=1; continue) in the following loop. ret1, ret2, n = 1, 0, 0 while n < m n == n0 && (n+=1; continue) ret1 *= z+n ret2…
4
votes
0 answers

RestTemplate, PUT method, and Expect: 100-CONTINUE

I'm a newbie to resttemplate and how it is backed by Apache http classes. So at first I thought all I needed to do was manually create http headers with Expect: 100 Continue in order to start implementing a PUT method using that feature. In my case…
paul
  • 113
  • 4
4
votes
1 answer

Why does Rust's example guessing game allow a match statement with varying return types?

Looking at the guessing game example from the intro book, specifically the part where you use a match statement to perform error-handling: let guess: u32 = match guess.trim().parse() { Ok(num) => num, Err(_) => continue, }; Why doesn't it…
Nathan Pierson
  • 5,461
  • 1
  • 12
  • 30
4
votes
3 answers

Continue loop Inside if statement vs. using the negation of the if statment inside the loop

For example lets consider the following 2 codes: for (i = 0; i < 1000; i++) { if ( i % 2 != 0) { continue; } else { ... } } and for (i = 0; i < 1000; i++) { if (i % 2 == 0) { ... } } Both…
Muaz
  • 65
  • 1
  • 6