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

Understand how CONTINUE works in Javascript?

I'm reading an article on the MDN website about loops and iteration. I'm trying to understand why we are getting the 1, 3, 7, 12 as a result from the following?: var i = 0; var n = 0; while (i < 5) { i++; if (i == 3) { continue; } n +=…
theAussieGuy
  • 157
  • 1
  • 2
  • 11
-2
votes
1 answer

Technical PHP - break and continue in the same loop

It is possible to use break/continue in 2 loops without variable ? (no continue 2; or break 2;) Example doesn't work : while(1) { // some code while(2) { // some code if(expr) { break; // break while(2) continue; // continue…
Jeremy
  • 279
  • 2
  • 13
-2
votes
7 answers

Python : count function does not work

I am stuck on an exercise from a Coursera Python course, this is the question: "Open the file mbox-short.txt and read it line by line. When you find a line that starts with 'From ' like the following line: From stephen.marquard@uct.ac.za Sat Jan 5…
-2
votes
3 answers

Issue with do-while loop, but can't seem to find it

Can someone tell me what is wrong with my code. If the user enters a negative integer, the program should keep telling the user to enter a positive until he does. I think it's the logic inside my do-while loop, but not sure. import…
EdtheBig
  • 161
  • 1
  • 2
  • 7
-2
votes
2 answers

get output 'during' a long foreach loop - not just at the end of last item in loop

i have a long hours working foreach loop which outputs correctly at the end when all items are processed.. foreach ($matches[0] as $map_link) { if ($map_link!='' && $i < $max_tags ) { include('reg-process.php'); } $i++; …
Shahram Mohseni
  • 65
  • 1
  • 1
  • 8
-2
votes
2 answers

JS if else vs if and continue within a loop

I have some code that looks like this: for(...){ if(something){ ...; continue; } for(...){ ...; } } Now I was wondering if it would be a better solution to replace the continue with an else block that…
Grim Dago
  • 11
  • 1
  • 6
-2
votes
1 answer

why does python loop continue work differently from other programming languages

in other programming languages when a continue is met in a loop it doesn't run the code below it and just does the next loop based on the condition set. Yet in python it would actually not trigger the continue as much as 3 times on the same exact…
SSpoke
  • 5,656
  • 10
  • 72
  • 124
-2
votes
4 answers

I wonder whats happens when if(i%2) what does it checks to come to continue. It misses == but it prints out the sum as 20? Why?

#import int main(void) { int sum,i; sum = 0; for(i=0;i<10;i++) { if(i%2) continue; sum+=i; } printf("\n%d",sum); return 0; } How does if(i%2) works in the above code?
Jonas Bo
  • 135
  • 1
  • 2
  • 6
-2
votes
1 answer

Illegal Continue: Javascript

I have a two for loops checking two sets of items. I have the following code: for(var key in powder){ for(var key2 in powder){ if(key == key2){ continue; }; [...] } [...] } ([...]s are unimportant info.) But, javascript…
Fuzzyzilla
  • 356
  • 4
  • 15
-2
votes
2 answers

How are these continue statements affecting my code?

I have been working on this little program in Visual Basic 2013 in an attempt to create a sort of tiered structure for user-input commands. Basically, I want the first of a two word input to direct the program to an area of code with a set of…
-2
votes
1 answer

Why is it my txt file keeps looping non stop?

I have been rushing my assignment and I found this bug when I'm doing a removing procedure of the membership. So, what's wrong with the code? Eventually, when I key in the member ID, it keeps on looping non stop. I tested it with a println and it…
user3900009
  • 113
  • 2
  • 4
  • 12
-2
votes
1 answer

Clarification about break function and continue function

Below is my while loop. What will happen if fgets == NULL and what will happen if I use continue and fgets == NULL ? Explanation expected. while((len = recv(sock, server_reply, sizeof(server_reply), 0)) > 0) { printf("point1\n"); …
user3751012
  • 533
  • 1
  • 8
  • 20
-2
votes
2 answers

Continue loop not working correctly

I have two continue loops in the below program- each time when a user enters 'X' or 'x', the program is supposed to again ask the user for input, ie the program is supposed to keep working normally. However, in my program, on entering X/x, it…
Manish Giri
  • 3,562
  • 8
  • 45
  • 81
-2
votes
2 answers

passing to another loop in python

word1 = 'index.php/1' word2 = 'index.php/2' try: tentativa1 = urllib2.urlopen(site + word1) tentativa2 = urllib2.urlopen(site + word2) except URLError as e: tentativa1 = e tentativa2 = e lista = [tentativa1, tentativa2] …
Milbol
  • 77
  • 7
-2
votes
4 answers

rewrite c expression without continue and break

In a school exercise (on paper) i've this question: 5) rewrite the code without using continue and break: for (i = 0; i < N; i++) { scanf("give me an int %d", & a); if (a < 0) { continue; } if (a == 0) { break; } …
malgaboy
  • 33
  • 1
  • 5