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,601
questions
1
vote
1
answer
31
views
Break out of inner loop in a nested loop (BASH)
I decide to play around loop just to understand how loops work in bash.
But I am the one who got played.
All I know is the the break call helps to stop a particular loop
echo "For loop begins&...
0
votes
1
answer
35
views
Is there any keyword that will terminate or stop the simulation when the output reaches a specific value in open modelica?
I want to stop the simulation when my output reaches a certain limit or value irrespective of the simulation time. Let's take an example my output is 'prod' a variable which has the product of two ...
0
votes
1
answer
33
views
Cancelling input command upon user's request
I am a beginner. I am creating a very basic calculator.
I want to break the program when the user gives the command as "STOP". Here's my code:
while d=="yes" or d=="YES" ...
0
votes
0
answers
7
views
Xamarin architecture classes links breaks
I am new in mobile development and trying to learn it. I have started with default project type and add a new page in my view. In that page whenever i am trying to add a listviewit is showing me ...
1
vote
1
answer
48
views
How can I get out of two loops in Python, not only the inner one? [duplicate]
When the answer is "Non", i need to get out of both if loops to continue with the program and i dont know how to do so, it only breaks from the inner one.
this is my first proyect and im idk ...
0
votes
1
answer
66
views
Ruby Invalid break (SyntaxError)
I have an issue with very simple piece of code:
def cond(x,y)
if x =~ /#{y}/
puts "ok"
else
puts "not ok"
break
...
-1
votes
1
answer
55
views
Breaking nested loops and iteration [duplicate]
So here's simple structure of my code:
while condition:
for i in range(num):
for j in range(num):
if arr[i][j] == something:
#DO SOMETHING
#...
-3
votes
2
answers
35
views
break in running program in python [closed]
when i run this code in terminal** i should prees" enter " key to run after line 6 **
i dont know the problem
i'm in the learning python proccess
thank all of you in advance........
print(&...
-1
votes
1
answer
60
views
i can't exit while loop without using exit(). Neither break nor return don't exit the loop?
machine = True
money = 0
def game():
global money, machine
while machine:
order = input("What would you like? (espresso/latte/cappuccino) ") # Gets order
machine = ...
-1
votes
2
answers
81
views
Usage of break in for loop
I am new to programming and I came across these two similar problems:
Example 1:
for i in range(10):
if i == 5:
break
else:
print(i)
else:
print("Here")
Output:
0 1 2 3 4
...
2
votes
3
answers
49
views
I need to remove the elements with repeated letters in the string
String1 = “Python is an interpreted high level general purpose programming language”
List1 = String1.split()
for i in List1:
for j in i:
if i.count(j)>1:
List1.remove(i)
...
2
votes
4
answers
113
views
How to exit an outer loop in C (without ++)?
In Java, it is possible to escape from an outer loop using such a construct:
int[][] matrix;
int value;
...
outer: {
for(int i=0; i<n; i++)
for (int j=0; j<m; j++)
if (matrix[i][j] ==...
-3
votes
1
answer
20
views
When Infinite Loop is opening at same time in Redhat Linux then how to stop it?
when some one attack like DDOS or Dos in our computer
for example someone like hacker let's say run infinite loop in your terminal to open the gnome-terminal
code:--
while :
do
gnome-terminal
done
...
0
votes
0
answers
14
views
How to display broken Japanese text correctly of exported PDF using dompdf?
I would like to export Japanese PDF using Dompdf.
Currently, PDF export is working correctly.
`$dompdf = new Dompdf();
$html = mb_convert_encoding($html, 'UTF-8', 'UTF-8');
//$...
0
votes
2
answers
64
views
Why does break work in switch blocks but not if-else blocks in C? [closed]
Just beginning with C and noticed this detail. Not a pressing question, just curious.
I tried searching for the answer but couldn't seem to find an explanation.
(not sure what else to say, this ...
0
votes
2
answers
123
views
What is the benefit of 'break' in 'switch' statement (Dart Language)?
When I write this code
void main() {
var age = 18;
switch(age){
case 18:
print("Age is 18");
case 22:
print("Age is 22");
default:
print("...
1
vote
3
answers
55
views
break statement does not stop executing while loop Immediately in java
I am trying to run a program that asks the user to list some values. These values will then be stored in a list and once the user types 0 the loop should terminate and the program should find the ...
1
vote
2
answers
62
views
Cypress - How to break out of .each loop with an if/else
Is it possible to break out of nested .each loops from an if-else statement?
I'd like to:
Get the text from each element
Check if it is included in an existing string
As soon as a substring that isn'...
-1
votes
2
answers
52
views
How to fix Value error in a while loop in python
I wrote a little program with a while loop statement. All lines run perfectly fine except for the last line of code which should break the loop. It always displays an error whenever Python tries to ...
0
votes
1
answer
35
views
using Break with list / dictionary comprehension in Python [duplicate]
I want to get the grades of student based on there marks, while using for and if i can use break when the first time numbers are greater the specified grade the program is
numb = int(input(&...
0
votes
1
answer
51
views
Python While loops with break statement
I have these 2 examples of while loops I read from the book 'Automate the Boring Stuff with Python",
the book labeled this first one
"An annoying while loop"
names = ''
while names != '...
-1
votes
3
answers
77
views
where to set "break" in nested loop
I am learning about nested loops and I have come across the use of break. I don't quite understand where to place break in the nested loop to get the correct output.
I have tried three different codes,...
0
votes
0
answers
31
views
if statement not following its condition [duplicate]
I'm trying to have it so that if someone inputs anything besides 1, 2 or 3 they have to go back and input 1 2 or 3 however when I put 1, 2 or 3 then it still happens. If they input 1, 2 or 3 I would ...
0
votes
1
answer
55
views
VS Code don't read break in if statement
In my code, VSCode don't read break in if statement when entered 0 and don't skip to last for loop.
My syntaxes are right, I debugged but it doesn't break out of the loop.
from contents import pantry, ...
0
votes
0
answers
12
views
Can i break out of a while loop while in a catch block?
So i got some code snippet that looks like this. The question is now, can i exchange the return right here with a break to get out of the while loop?
I'm asking cause according to our guidelines there ...
-1
votes
1
answer
49
views
Trouble ending a loop
I'm fairly new to Python and I have to do this exercise where I need to simulate a cat walking on a few lines. If the cat finds a treat ( * ), he eats it, and the position is replaced with floor ( _ )....
-3
votes
2
answers
65
views
Why it works in Javascript but in Python dont?
I made the same code in Python and JavaScript and in JS it works but in python dont
This surprises me because I'm learning javascript, python is the language I believe I know the most and I'm not able ...
0
votes
1
answer
25
views
Issues with breaking loops and static variables in Android Studio Java code
I run into two problems writing java code in android studio.
here is my code:
static String price, title;
private void initData() {
adList = new ArrayList<>();
int i=0;
...
0
votes
1
answer
68
views
Stopping a Python while loop in a text-based adventure game
I am writing a text based adventure game in python language and unfortunately I can't stop the game. I tried writing the code --->
def GAME_RESTART():
i = input("would you like to play ...
0
votes
1
answer
127
views
How to Read A Text File on Python and Stop When Encountering A Certain Value and Continue Reading After Value is Encountered
I have a text file with this format:
0 -82.871 2.52531 36.64 138 96.05
0 -76.1014 2.52577 35.36 137 83.9
0 -76.1869 5.57562 35.36 137 62.8
0 -18.1623 -11.6886 386.08 411 200....
0
votes
0
answers
84
views
How do you issue a 'break' command in a nested while/do/done containing multiple loops?
#!/bin/sh
set -x
#########################################################################
# This script will export a listing of all devices and where each device
# lives (...
-3
votes
1
answer
29
views
Programme to print all the Prime numbers within a range
So basically the aim of the programme is to print the prime numbers between two numbers.I did find the solution to the problem in the internet but i cannot understand what was worng with my code,I ...
1
vote
1
answer
43
views
What will be the effect of using 'break' statement within a 'for' in the torch forward module ? -- torch graph
I want to develop a GRU-based model for variant length input data. So I think I should use the while statement in the forward and then break it when all of the sequences were processed. Will it affect ...
0
votes
0
answers
30
views
How use just one of an element of two float tuple
I am trying to enter by keyboard one of the two types of tuples that contain float numbers as well as the position of each float number of the chosen tuple to then be multiplied by an integer number ...
0
votes
0
answers
56
views
Infinite loop breakdown
Help with an infinite loop, I want to stop the function if it equals the first elements in the list in existing_list.
existing_list = [[ '10000714484,10000714481']]
A = df_test['A']
B = df_test['B']
...
0
votes
2
answers
52
views
for loop break statment
city_flight = input("London, Edinburgh, Liverpool, Manchester"'\t').lower()
for city in city_flight:
if city != "London" and city != "Edinburgh" and city != &...
-1
votes
1
answer
39
views
How to fix a looping and a break bug within a Rock, Paper, Scissors program?
I wrote a basic program to run rock, paper, scissors in Powershell.
import random
print("Lets play Rock, Paper, Scissors...")
print("Type 'quit' to quit the game")
pwins = 0
...
0
votes
2
answers
84
views
Using " break " statement in " for loop " not working
#include <stdio.h>
int main()
{
int i; // i wanted to print numbers each with difference of 2 up to 18
for (i = 0; i < 25; i++)
{
printf("the number we get ...
0
votes
1
answer
36
views
Is there a better way to terminate the program other sys.exit()
This is the code i wrote for a guessing game in Python. It asks the user to guess the number between 1 and 1000. If the user is is correct or runs out of guesses, it will ask the user if he wants to ...
-1
votes
2
answers
33
views
How to use break and cin in array loop string in c++
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
string day[]={"Monday", "Tuesday", "wensday", "Thursday", "Friday&...
0
votes
1
answer
43
views
Why does the break statement not work while scraping reviews with Selenium and BeautifulSoup in Python?
I am scraping reviews with Selenium and BeautifulSoup in Python but the break statement does not work so that the while loop continues even after arriving at the last review page of a product. From ...
0
votes
2
answers
61
views
I don't understand the behaviour of the break statement in my for loop
I'm programming a Python exercise task and wondering about the behavior of my code. Im a C and C++ programmer and totally lost here. Can someone tell me why Python does here what it does?
this code ...
0
votes
1
answer
40
views
Is there any error in R code to get only prime numbers from 3 to 100?
I want to get prime number from 3 to 100, only using 'if', 'for', 'break', 'next'.
When I run the code, nothing shows up.
Is there any error in the code?
for (i in 3:100) {
prime <- TRUE
for (k ...
0
votes
2
answers
73
views
JavaScript jump to label
I'm trying to make a function that validates user input and return true if there are no mistakes or false (and display a message) if there is a problem.
If an error found, there is no need to check ...
-2
votes
1
answer
83
views
indentation to make software control flow apparent. What do you think about it? [closed]
How many times have you encountered a function with a return statement deep within the code? Or failed to notice a break or a continue in a loop? While I have not been blindsided by return recently, I ...
0
votes
0
answers
19
views
allow next line on wordpress product exerpt. Tried to use shortcode [br], works on 1st page but not the 2nd page
I follow this blog post (https://www.wpexplorer.com/wordpress-line-break/) to add a snippet to enable the shortcode [br] so that the product exerpt allows line break.
I have more than twenty products. ...
0
votes
0
answers
10
views
How to keep an image within two <br> tags no matter the size of the screen?
How do I keep an image in between two <br> tags even when the size of the screen can change?
I resized my images to perfectly fit in between two <br> tags one one specific screen, but it ...
0
votes
0
answers
5
views
Output is not correct; player turn and player bank do not output correctly
I am making a 2 player hot seat style dice game. Players take turns throwing 1 die. Each round you choose to roll or bank. Round score cant go over 10 or it ends the turn and the other player goes. ...
0
votes
1
answer
75
views
Why my code doesn't output the value of the parameter when the for loop is left using break? [closed]
#include <iostream>
using namespace std;
void rest(int x, int y, int n, int& k)
{
for(int k = n; k > 0; k--)
{
if(k % x == 2 && k % y == 2)
{
...
1
vote
1
answer
98
views
Add break in footnote gt table
I would like to add some breaks in the footnote of a gt table. When I add \n or <br> it doesn't work. Here is some reproducible code from the link:
library(gt)
sza %>%
dplyr::filter(
...