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

What is this "continue" example doing in Python?

So I am in the process of learning python and I ran into this code that is confusing me. var = 95 for items in range(0,100): if var < 10: continue elif var == 10: print("hit") elif var > 10: print("passed") …
Capurnicus
  • 8,171
  • 5
  • 18
  • 11
-3
votes
2 answers

Could I get clarification on the continue statement?

I want clarification on the continue statement. #include int main (void) { int i; while (i < 10) { if (i == 4) { i++; continue; } printf("%d\n", i); i++; } return…
ddp17
  • 41
  • 4
-3
votes
1 answer

Break operator with continue c++

My code: using namespace std; int main() { int n; int total = 0; cout << "Enter a value: "; cin >> n; while (total + n <= 1000) { cout << total << " "; total = n + total; continue; } } I need…
svep
  • 1
-3
votes
2 answers

PHP consecutive subtraction two arrays

I have 2 arrays like this a = Array([101] => 5,[109] =>100,[220] => 50,[231] => 45,[245] => 90) b = Array(['PRO'] => 12,['LOG'] => 15,['DEV'] => 100) I want to consecutive subtract 2 array and result like this c = Array([101] => 0,[109] => 0, [220]…
ngoCham
  • 17
  • 3
-3
votes
1 answer

Having some trouble with a 'continue' and 'break' error in my code

enter image description hereokay so this a question on quiz I am taking currently. I don't want to know the answer I just want to know why I keep getting an error when I try to use break or continue in my loop. Is it a syntax thing or did I just…
-3
votes
1 answer

Using try, catch and a label for the first time

We just covered the try-catch topic in last night's lecture. It's not required to put it in this assignment, but I thought I would give it a shot. I've been struggling with this for a while. Using a continue statement kicked it back to the start of…
mtlchk
  • 11
  • 6
-3
votes
6 answers

What doesn't my C++ program work when I try to use recursion?

I need help with the following c++ code, trying to add a continue at the end of the program so that it will make a user specified dimension for rectangle and ask the user to redo the program again. Compile and ran it without the silly if and else…
user352258
  • 45
  • 3
  • 10
-3
votes
1 answer

PHP : Continue get me out

Why my second if is never executed ? It seems like the continue sentence get me out of the foreach. I have tried the elseif without success. foreach($columns as $i=>$column) { // Check if column exists $sql =…
PM1625637
  • 102
  • 10
-3
votes
2 answers

what is the logic behind its output ? Its giving the same output for both Break and continue

First of all, I'm confused about output? How this output can possible? I have tried many logic but didn't get a universal logic/ with 'break; statement: for (var i = 2; i <= 8; i++) { if (i == 5) { break; } i++; …
Suraj Arya
  • 27
  • 3
-3
votes
4 answers

Continue outside of loop error despite it being inside the loop

I can't run this code because of a continue outside loop error. I have looked online and found that people had issues due to having an extra semi-colon. I don't have that issue but yet I still get this error. public class GuessingGame { int…
Lse Library
  • 13
  • 1
  • 5
-3
votes
2 answers

Use continue key word to processed with the loop

I am reading data from excel file(which is actually a comma separated csv file) columns line-by-line, this file gets send by an external entity.Among the columns to be read is the time, which is in 00.00 format, so a split method is used read all…
Mronzer
  • 399
  • 1
  • 7
  • 18
-3
votes
2 answers

Prime number(Python 3)

My goal is to build a programm, that says is a number prime or not. A positive whole number n > 2 is prime if no number between 2 and sqrt(n) divides n. Here is my code: import math def main(): print("Prime number or not") try: …
Daniel Yefimov
  • 860
  • 1
  • 10
  • 24
-3
votes
1 answer

Skipping first value in the forloop

I have a forloop in javascript, which has 120 values, what i want is, i always want to skip the first values which the loop holds and always want to jump to next value which loop will generate, as i have several if conditions, value of i won't be…
Abbas
  • 4,948
  • 31
  • 95
  • 161
-3
votes
2 answers

How can i break a foreach statement, echo something else and then continue

I am getting two different arrays arrays of data from MSQL database, first array from my blog post table containing 15 rows/items, and the second array from advert table containing 3 rows/item. i want to foreach the first 5 set of data from blog…
sirlouis
  • 65
  • 1
  • 9
-4
votes
5 answers

I can't put "continue" command in a definition?

Let's say, def sample(): if a==1: print(a) else: continue for i in language: a=i sample() I want to use this function in a loop, but the continue command gives me an error because there is no loop. What can I do?