Questions tagged [break]
A break statement is a flow-control feature provided by most programming languages that allows for an early exit from a loop; once a break statement is reached, its enclosing loop is immediately exited.
2,207
questions
0
votes
0answers
59 views
Python Loop not breaking corectly
I believe that the cause is do to my loop being recursive, however I am not positive on that. Basically I have plethora of functions that are activated by a menu. Calling the functions works fine, the ...
2
votes
1answer
30 views
Stop statement outside a SAS data step?
Instead of commenting in and out large blocks of code when developing, I am looking for an equivalent to the stop statement outside a data step which stops a SAS script at a certain point, ideally ...
1
vote
3answers
61 views
How to break iterating over a list in FSharp?
I want to stop iterating over a List when the first item matches a condition.
let list1 = [1; 2; 3; 4; 5; 6; 7; 8; 9; 10]
let list2 = [1; 2; 9]
list1 |> List.iter (fun item ->
match List....
-1
votes
3answers
36 views
Stuck on Automate The Boring Stuff Chapter 2- Continue Statement
I'm currently on Chapter 2 of Automate the Boring Stuff and am stuck on Continue Statement. The example given is if the name inputted is 'Joe' and the password is 'swordfish', the program would print '...
1
vote
0answers
43 views
Android TextView automatic line break at weird place
I'm stuck on a issue with automatic linebreak at weird place in a multiline TextView. Does anyone have an idea on what I am doing wrong ?
Here's the xml layout:
<TextView
android:id="@+id/...
0
votes
1answer
42 views
what am i doing wrong with my while true try except else loop
im trying to get my bot to go onto a website and if the website is down or not running properly for my bot to reload the page, and to loop that until it finds the clickable element by xpath, and then ...
1
vote
1answer
35 views
List-2 > sum13 coding bat problem: 'int' object is not iterable
I am having a problem with my code. The question is:
Return the sum of the numbers in the array, returning 0 for an empty array. Except the number 13 is very unlucky, so it does not count and numbers ...
0
votes
1answer
28 views
how to prevent an error from breaking a loop
if a string contains less than the number of characters you're trying to remove with this command:
(4 characters in this example)
variable1=${string::-4}
and this command is within a loop,the error ...
0
votes
1answer
26 views
What difference does it make to use the increment operator before the continue statement in a while loop? (JavaScript)
I was trying to code along a tutorial on using the "continue" statement in a while loop. In the tutorial, the code was written as shown below and it worked fine.
...var x = 1;
...
-1
votes
1answer
31 views
Why this loop for finding the prime no is not executing the way expected?
def prime_no():
number = int(input("Enter your number for which you wanna generate prime factors: "))
prime = [2,3]
numb = [*range(4, number + 1)]
for x in numb:
while x > number:
...
0
votes
0answers
30 views
Is my code recursive If I use the break command?
I'm learning about recursive and Greedy algorithms, this code separate the change needed for a original amount. I tried using a recursive algorithm but the code wasn't working properly until I added ...
-4
votes
2answers
38 views
it may seem like a silly question but it's confusing to me regarding the (++) and it's position in php
this code prints to 10##
<?php
$value=1;
do{
echo $value."<hr>";
if ($value>=10) {
break;
}
$value++;
}while (true);
?>
But this code prints to 9
<?php
$value=1;
...
0
votes
2answers
48 views
how to reduce run tiime for a simple if-else-while program
i had just started learning python,so i was practising some code at codechef
one of the problem i was trying was https://www.codechef.com/problems/CHEFEZQ
"Chef published a blog post, and is now ...
0
votes
1answer
44 views
includes() not matching strings when iterating with for loop
I have this simple for loop that is supposed to break and run a function (name_display) if it matches a string (trackName) inside of another string (url). The track_list is a Nodelist of A tags with '...
3
votes
1answer
66 views
Why does the break statement not work here?
I just wanna preface this by saying that I'm a beginner and I'm sorry if this is a stupid question/obvious mistake.
I'm making a human vs computer tic tac toe game , and the break statement is not ...
1
vote
0answers
33 views
Why does this JS prompt terminate the while loop it is inside of? [duplicate]
This while loop will only iterate once when run. If I replace prompt("Enter anything") with a value, the loop functions properly. How can I use a prompt with a while loop and prevent it from ...
0
votes
0answers
10 views
Python : Count lines and break after the list ended
hello
i have a situation here that i need to count how much of lines on the "em.txt" , i tested readlines() fonction, but the problem is the script still doing loop and repeat after lines ...
0
votes
1answer
36 views
Why does the bubble sort program show the garbage value when using “break” in for loop?
This code will take the elements of the array from the user and then sort it. The user input limit is 20. I have an issue with a specific line which is if (a[i]==0)break; if I use break here the ...
0
votes
2answers
57 views
What to do about this loop? [closed]
char restart = 'y';
while (restart == 'y')
{
cin >> restart;
cout << "great keep playing\n";
}
cout << "thanks for playing\n";
When I run this code it ...
1
vote
1answer
29 views
How can i break a for in loop from nested forEach Function in Javascript?
I have a this loops
for (var key in params) {
if (Array.isArray(params[key])) {
params[key].every(function(item) {
let value = something(item.start, item.end);
if (value === item....
0
votes
2answers
55 views
Python infinite loop with for else
I am writing a function to count primes. I try to use a for-break-else framework nested in a while loop. However, I got an infinite loop. I knew the else is not with the right indentation. After I ...
0
votes
0answers
35 views
Python loop: break and setting loop indice to max value yield different results
I'm trying to solve a problem on codeforces, but ran into an issue:
The following codes don't yield the same results (value of nb). Only the 4th line before the end differ: replaced break by j=i-1.
n =...
-1
votes
1answer
45 views
why is the continue out of loop for my bubble sort code and how do i fix the problem/ why is the bubble_sort(undefined)
`def bubble_sort(numbers):
# We set swapped to True so the loop looks runs at least once
swapped = True
while swapped:
swapped = False
for i in range(len(numbers) - 1):
if numbers[i] &...
1
vote
2answers
50 views
How to resolve the following program with a for loop into producing an appropriate output?
The following Java program is supposed to manipulate a string input by the user in such a way that the user will decide which character needs to be replaced with another and just the last character ...
0
votes
2answers
63 views
How to end the following loop without using the break function?
The following Java program is supposed to manipulate a string input by the user in such a way that the user will decide which character needs to be replaced with another and just the first character ...
0
votes
1answer
47 views
Custom class preventing loop exit when condition is met
I am trying to break out of the outer while loop when the user inputs no (with any capitalization; I use the upper function). Currently, when the user inputs a "no" the while loop is run ...
0
votes
2answers
21 views
How to compare particular element in list python3?
l1= [['1', 'apple', '1', '2', '1', '0', '0', '0'], ['1',
'cherry', '1', '1', '1', '0', '0', '0']]
l2 = [['1', 'cherry', '2', '1'],
['1', 'plums', '2', '15'],
['1', '...
0
votes
1answer
50 views
JAVA : How do I input a ( < 0 ) to break the code?
2 weeks in. I need to break the while loop with a negative integer but I've been unable to implement it successfully. This is my original code before I editted left and right to no avail. The values ...
0
votes
1answer
57 views
How can I wait for an input while something else happens at the same time?
I've been having a really hard time putting this problem into words. What I'm trying to do is to have a while-loop constantly running, unless I give a 'stop' command.
I'm making a fishing mini-game in ...
0
votes
0answers
20 views
Creating gaps on x-axis for density plots in ggplot2 [duplicate]
library(datasets)
library(tidyr)
library(ggplot2)
data(mtcars)
wd_dat<-gather(mtcars,fun,val,c("hp","drat","wt"))
wd_dat<-wd_dat[,9:10]
p<-ggplot(wd_dat, aes(x=...
1
vote
2answers
29 views
Removing a break line from the form text input
HTML:
<div class="form-row">
<div class="col-md-6 mb-3">
<label for="validationCustom03">Service</label>
<input type="text&...
1
vote
1answer
62 views
Flutter Progress_state_button - how to change button state
I am trying to use the progress state button in flutter. From the pub.dev docs, the widget should be set up as follows
Widget buildTextWithIcon() {
return ProgressButton.icon(iconedButtons: {
...
1
vote
1answer
44 views
How to break if loop and start over from next element in python
Following code gets single value as a and b as pair of values from user and then if in the first pair B[0,0]<B[0,1] will skip the first pair and then 2nd condition will continue till the condition ...
0
votes
3answers
42 views
JavaScript Loops Break and continue (JetBrains exercise)
You are given an array of numbers called numbers. Calculate the sum of numbers and return it from the function. If the next number is equal to 0, the program must stop processing the numbers and ...
0
votes
0answers
12 views
Excerpt argument via shortcode wordpress
i am trying to build wordpress plugin in which excerpt word limit is to be defined via shortcode but my shortcode is not working with this. it display complete post instead of excerpt. any help is ...
2
votes
3answers
42 views
Trying to break in a while loop for a calculator program while accepting int and str values
I am making a calculator program while I'm learning python, I learned Java in high school and don't know any advanced python functions yet, so try not to use anything too advanced, but lets get to my ...
0
votes
2answers
51 views
powershell come back to the previous line break
I am looking to create a script allowing me to correct the format of a log file that has been incorrectly generated for several months which gave the format below
xx-xxx-20xx xx:xx:xx INFO : xxxx-x : ...
0
votes
1answer
42 views
while for loop combination can't end up while loop
I'm developing a script to check if a data frame's column's sum is over three with a certain interval.
loc_number = 10 # start loc image number with 10
k = 2
while k < 3:
for i in range(0, int(...
1
vote
1answer
42 views
Unable to return boolean value properly from a function
I am a very new python learner and trying to make a tic tac toe game in python. With my current lines of code I am unable to return boolean values properly.
board = ['-', '-', '-',
'-', '-', '...
0
votes
1answer
39 views
Program does not terminated properly convert binary to decimal
I write a c program to convert a binary number to a decimal number.
This is my code
#include<stdio.h>
int q[6],f,r;
int main()
{
int a,v,i,m,sum=0;
f=r=-1;
for(i=0;i&...
-1
votes
1answer
56 views
Python: Checks user input guess any item
I am newbie, and I need help, please. I am asking user to guess any item, if it's not correct - keeps asking. However, I am trying to do many ways but cannot get the code right. Sometimes, it's just ...
-2
votes
1answer
27 views
Python while loop issue - repeats unexpectantly
I'm trying to write code to ask a series of questions and if the user answers "No", then the while loop breaks and a statement prints. This part of my code works. However if the use ...
0
votes
3answers
94 views
how to exit a while loop in ruby using the enter key
I am trying to write a program that keeps adding user input to an array until they hit enter on an empty line. Then it sorts the array in alphabetic order and display the sorted array back to you. It ...
1
vote
3answers
82 views
Moving to next iteration of external loop from inside the nested loop Directly
I have a nested loop and in the internal loop I am doing a condition check and if that condition check Is satisfied i want to jump to the next iteration of the external loop.
It goes something like ...
1
vote
2answers
88 views
How to break a for loop from inside an if statement in Julia?
I am trying to translate a python modelisation (not very effective) into a Julia code (more useful in this context) but I didn't find how to break a for loop and how to print a value in this context.
...
0
votes
2answers
26 views
Script returns wanted strings, but with '\n' put after it
I have written this piece of code for a script that should check whether a word contains all vowels (so, e, u, i, o, a), case-insensitive:
def words_all_vowels(filename):
"""Returns ...
1
vote
0answers
7 views
Test connection between devices on a network
Is it possible to test connections between devices on a network? How can you find out where the break in the connection is? Example of a network
cloud server <-----> modem <----> router &...
0
votes
1answer
200 views
When downloading a .CSV file the CRLF line breaks are missing, but Excel can load it fine. Can I fix the CRLF without loading Excel?
I am retrieving daily logs from a system in the format of a .csv file. I want to import these to my database. The issue is that, for some reason, these .csv files seem to lack CRLF line endings (it's ...
0
votes
1answer
40 views
How do I break out of a While True Loop and Go back to the Loop [duplicate]
So each request it sends keeps printing
{"success":false,"code":7,"message":"Ad creation cooldown has not elapsed"}
and everytime it prints this I want it to ...
1
vote
1answer
80 views
What does Dafny know about loops with a break?
I am used to loops
while Grd
invariant Inv
{ ..}
assert Inv && !Grd;
with out any break Dafny knows that Inv && ! Grd is true but:
Dafny does not check the loop invariant after a ...