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
2 answers

Continue 2 levels deep in JS

Consider this very simple code: someLabel: for (var i=0; i
Rudie
  • 52,220
  • 42
  • 131
  • 173
3
votes
6 answers

Difference between "no statement" and continue

In the code below, please take a look at the part which has the 'continue' statement. What difference would it make if I remove 'continue' statement and I put nothing in the place of it. int prime_or_not(int x){ int i; if (x == 1 || x ==…
Göksenin Cakir
  • 186
  • 1
  • 3
  • 9
3
votes
4 answers

Remove the second 'o' from the statement 'helloworld' in python

Beginner in python here: for l in 'helloworld': if l == 'w': continue lnew = l lnew = ''.join(lnew).replace('o', '').split() print "The letter is", lnew I am trying to remove the letter 'o' after letter 'w' from…
3
votes
2 answers

Infinite for loop using continue

I'm writing a code that will run through each bin in a histogram and check if there are any non zero bins. If there are, it throws out an error message. My issue is, I want it to skip a bin because this bin should not be empty, but check all the…
CStarAlgebra
  • 197
  • 2
  • 10
3
votes
2 answers

Control flow within an eval function in Matlab

If I include a continue as a parameter of an eval() instruction, it does not work as expected. For example, when executing the following code: listParam = {'a','b','c'}; a = 17; b = NaN; c = 4; for ii=1:numel(listParam), eval(['if…
tashuhka
  • 5,028
  • 4
  • 45
  • 64
3
votes
5 answers

PHP - else, 'escape' nesting and skip to elseif

I wasn't too sure how to title this question - Here's a snippet of what I'm doing: = 1 && $membership = 'active') { if ($when_next_allowed > $today_date) { $output = 'You cannot renew your membership for…
Super Cat
  • 1,547
  • 1
  • 18
  • 23
3
votes
2 answers

Can't use "continue

I am trying this code: entLoop:for(var i:*in entities) { for(var i2:*in ignoreEntities) { if(entities[i].type==ignoreEntities[i2]) { continue entLoop; } } } Why is it not working? The error is: Target of continue…
user216441
3
votes
5 answers

What happens when loop gets to the end?

I am python beginner, with no previous programming knowledge. I apologize for the name of the topic, but I simply could not make a better one. Here is what I want: letter = "w" # search for this letter in the list bellow listL =…
marco
  • 899
  • 5
  • 13
  • 21
3
votes
2 answers

Javascript change for loop variable from within the loop

I have a for loop like so for (var i = 0; i < 100; i += 4) { // code with i; } I would like to change the value of i to a certain value from within the loop. I am aware you could use continue to change the value of i after evaluating the…
Patrick
  • 1,410
  • 2
  • 19
  • 37
3
votes
1 answer

Using continue to skip iteration in foreach from inside a swich

$arr = array('not want to print','foo','bar'); foreach($arr as $item) { switch($item) { case 'foo': $item = 'bar'; break; case 'not want to print': continue; break; } echo…
Toni Michel Caubet
  • 19,333
  • 56
  • 202
  • 378
3
votes
2 answers

Is there a way to set an option that will cause a PostgreSQL script to continue even if there are errors?

Is there a command to set an option that will cause a PostgreSQL script to continue even if there are errors? eg sometimes when I have a lot of data from a spreadsheet to insert into a table, I use a formula to create INSERT statements, and I copy…
vfclists
  • 19,193
  • 21
  • 73
  • 92
3
votes
1 answer

is there a way in PHP to restart a loop in a foreach, or change the test value in a switch?

if i'm looping over an array, and while in the middle of one of the loops i discover some small issue, change ...something..., and need to try again ... is there a way to jump back to the top of the loop without grabbing the next value out of the…
changokun
  • 1,563
  • 3
  • 20
  • 27
3
votes
1 answer

continue cannot be used outside of a loop (it isn't outside actually)

I dont understand why continue causes error here public void clear() { log.debug("Clearing hash"); // wow! while( hash.size()>0 ) { for(Map.Entry entry : hash.entrySet()) { clearingParents: { …
Suzan Cioc
  • 29,281
  • 63
  • 213
  • 385
3
votes
4 answers

C# for continue inside foreach

Possible Duplicate: continue and break with an extended scope i have one problem. I don't know how to call continue for "for" inside foreach. Code: for(int i = 0; i < ...; i++) { foreach(´´ .. in ´´) { if(,,.Value == null) // A! …
user1085907
  • 1,009
  • 2
  • 16
  • 40
3
votes
2 answers

Python script embedded in bash, does not exit

I'm having a curious problem. I have a bash script that is calling a python script within it. The python script executes successfully, but never fully terminates Content of Bash script: #! /usr/bin/env bash python python_script.py echo…