## How can I use while or for loop to count when the value exceeds the given number?

this my work I have a problem with the question is the last passenger should not be counted if their weight added to the total passenger weight exceeds the carrying capacity. Thanks. import java.util.*; public class Exam2 { public static void main(St

## Convert a for loop to a java recursive method

I'm trying to convert this loop to a recursive method. This iterative version works: (recursive attempt comes after that) public static int subCompareTwoCol(JobS j1, int index1, int index2, int indexTab1){ //Almost same method as above but with modif

## This python loop needs a solution

So, I have this code: path_list = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a0', 'a1', 'a2', 'a3', 'a4', 'a5', 'a6', 'a7', 'a8', 'a9', 'b0', 'b1', 'b2', 'b3', 'b4', 'b5', 'b6', 'b7', 'b8', 'b9', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'c7

## break a loop when you press enter

I'm trying to break the loop once Enter is pressed, while writing data to a file. This is what I have so far. I also don't want to limit the number of time the loop is run either... (example output is below) def main(): myfile = open('friends.txt','w

## A loop to add a list item without high memory performance?

Everybody, a =[0, 0, 2, 4, 6] x=5 This a list (a) and a fix value (x). I need a loop codes which must add with x every element of list and add this value with previous list elements in every loop ( loop must continue as x value). Other words result s

## Allowed memory size of 134217728 bytes out of print (allocation attempt of 42 bytes)

I am retrieving record from mysql table which return more than 0.2m number of rows per query, which obviously take lot of memory. in my case i have 8 GBs installed RAM on my system with SSD 256 GBs. When i execute my page it returns the following err

## Python script that runs an iterative google search and prints the best results and links

I want to write a python script that will pull the title and url of the top three links of successive google searches. For example, I want to be able to google "3 mile run", "4 mile run", and "5 mile run" and get the top thre

## How to continue from the beginning of the code when an exception is thrown?

I'm running a code that throws an exception,I want run the exception code continuously whenever the exception is thrown it has go to starting and should start the program from starting. Here is my exception method and mainYou need to put the try / ca

## Why does this loop print the same value every cycle?

This question already has an answer here: srand function is returning same values 1 answer I have the following loop in main() while (count < 5){ //with 2^15 as the lower limit srand(time(NULL)); ran_num = rand() % (65536 - 32769); //check READ ME Ci

## How to accept the user's entries multiple times and then run the rest of the script when they're done?

I want to write a script where a user can get a list of all of the files in a directory and then type in the full filename to view them. Right now, my script will let a user do this once and then it continues onto the next portion of the script. I wo

## Print values ​​in * instead of numbers

Please I'm having an issue on how to generate a star rating. What i mean is that, after a user has inputed values for rating parameters and the program has calculated the total rate, how will the program produce the result in stars and not in figures

## use a loop in R to output many files

My goal it to run all the files in a folder called "myname.output/" through a loop function to generate multiple CSV files each being myname1, myname2 .... etc This is what i have so far sample_d <- list.dirs("myname.output/", recur

## Find recurring number combinations in the number column

I have searched and found discussions and solutions to similar problems, but not quite or as complex as I'm trying to figure out. I have an access table which consists of two columns Draw Number and Number Drawn as shown below. Draw Number is repeate

## How can I create a back triangle in Java using for loops

I need to make a triangle that looks like this * ** *** **** ***** ****** ******* Currently i have a working one that looks like * ** *** **** ***** ****** ******* using the loop : public static void standard(int n) { for(int x = 1; x <= n; x++) { fo

## SQL 'while' to read data from a table in a variable

How could I write a while loop to populate data from a table to a variable to be used in a seperate query ? EX: select ITEM from Table1 ITEM A0001 B0001 C0003 D0005 E0032 If I can get all that results here under column ITEM to @var1 and then use it i

## R loop the image and create a vector of each row

New to R. I am trying to create a vector from each row in a dataframe, and name the vector after the position in the dataframe. Sample data: a <- read.table(text='keyword1 keyword2 1 "hello" "goodbye" 2 "foo" "y"

## How to tell ffmpeg to scroll through all the files in the directory

ffmpeg has concat option for this but all streams start working really bad and breaking sound after a day of streaming. I tried looking at loops but i couldnt figure out how to execute a loop with ffmpeg command so it transcodes all files in 1 direct

## Base class C # has a derived class member and loop

I have this class: public class GameData { public int[,] mat { get; set; } public int dim { get; set; } public int goal { get; set; } public Game game { get; set; } public GameData() { game = new Game(); } } And this two other derived classes: public

## How can I break a loop when a specific character has been hit?

Assume I have a loop like for(int i = 0; i < 100000; i++) { crunch_data(i); if(i_has_been_hit()) break; } and I would like to exit the loop whenever I hit i on the keyboard. Now the following approach won't work, since std::cin blocks: bool i_has_bee

## While the loop should put off concat strings, only output in the console and not concat? Ruby MongoDB Sinatra

I´m looping through an array and I want each part of the array to be displayed in my browser. While it finds the right entries and puts them in the console it won´t show them in the browser. I can make the first one or last one appear on the screen b

## Reading a socket in a while loop

I want to implement the following functionality while (true) { if client sends something process it else wait till something is send } I have tried the following but it didn't work , it process one thing and then stop working can anyone help me? I ha

## The C ++ output loop does not work

well its a simple project it does everything as it should minus it wont exit when it is suppose to. I have tried many different ways including goto statements I tried a if loop but got nothing but errors. The current code gives no errors just I dont

## List identified with another, using new elements in the loop

This question already has an answer here: python list by value not by reference 11 answers I have a list named MyList. I want to copy the list to a new one, then add items to the new one, so I do: MySecondList=MyList for item in MyList: if item==2: M

## The main number loop writes only & ldquo; 2 & quot; console. Java

I am more or less completely new to Java. I thought I would try to write a simple loop to output a list of prime numbers under 100 into the console, as practice - however as you can probably tell by the title of this question all it gives is 2 and th

## Access to the next value in a Twig loop

I have a problem to display the next line of a result in a loop using Twig : // Arkiglass/ProduitBundle/Controller/DefaultController.php <?php public function produitAction() { \$em = \$this->getDoctrine()->getManager(); \$query = \$em->createQuer

## Move in similar repetitions in if statements

I believe I'm asking a slightly different take on the perennial question of avoiding code repetition. The setup is fairly standard--a bunch of if statements taking similar actions. Below you'll find a short example. I'm trying to figure out the best

## Do & hellip; While () loop does not work well

I am prompting the user to enter data regarding cars. The Do...while() loop I am using works fine the first time, then does not work properly after the first time. The code is bellow, and I am using Dev-C++. Thank you for your help and time. #include

## How to use cURL to find subdomains containing specific strings?

I am trying to build a list of all the city pages on ghix.com, which does not have such a complete directory. To do this I am using their 'city id' which is unique for each city, but does not follow any particular order. I am using cURL and PHP to lo

## Break a & ldquo; for & rdquo; loop using & ldquo; break & rdquo; considered harmful?

Some days ago I started a quick open source project and, when some mates looked at the code on svn, one of them told me that using break statement inside a for loop is considered harmful and shouldn't be done. He added, though, that I would find seve

## Iteration on list slices

I want an algorithm to iterate over list slices. Slices size is set outside the function and can differ. In my mind it is something like: for list_of_x_items in fatherList: foo(list_of_x_items) Is there a way to properly define list_of_x_items or som