while-loop

Java SE do while loop issues

纵饮孤独 提交于 2019-12-04 06:37:09
问题 I have a problem with my java application when i compile my codes it says that it cannot find symbol roomLength . what the application supposed to do is prompt the user to input a room name then if it is "quit" then it has to close the program. otherwise it will prompt for the length, width and height of the room. if any of these dimensions is zero or lesser, it will reprompt for the dimensions again. class Room { private String name; private double length; private double width; private

Creating A Deck Of Cards In R Without Using While And Double For Loop

余生颓废 提交于 2019-12-04 06:33:47
I am creating a blackjack simulator in R. The code below succeeds in creating the deck(s) of cards that I want. (For those that play, I will deal with the value of an Ace later). My question is, is there a better way to create the deck that doesn't involve a while loop plus a double for loop? I have more of an issue with the double for loop. The while loop is likely unavoidable since the number of decks created is variable. I also initialize an empty data frame which I know isn't the best practice, however, the data set is so small in this case that it won't effect performance. And lastly, is

While loop executes only once

僤鯓⒐⒋嵵緔 提交于 2019-12-04 06:30:35
问题 I have a hard time figuring out why the while loop won't actually loop. It runs through once and stops. import java.util.*; public class mileskm { public static void main(String[] args) { Scanner inp = new Scanner(System.in); boolean continue1 = true; while (continue1 == true) { System.out.println("Would you like to convert m-km or km-m(km for m-km and m for km-m)"); String convert = inp.nextLine(); if (convert.equalsIgnoreCase("km")) { System.out.println("Enter the mileage to be converted.")

for-each vs for vs while

柔情痞子 提交于 2019-12-04 06:24:27
I wonder what is the best way to implement a "for-each" loop over an ArrayList or every kind of List. Which of the followings implementations is the best and why? Or is there a best way? Thank you for your help. List values = new ArrayList(); values.add("one"); values.add("two"); values.add("three"); ... //#0 for(String value : values) { ... } //#1 for(int i = 0; i < values.size(); i++) { String value = values.get(i); ... } //#2 for(Iterator it = values.iterator(); it.hasNext(); ) { String value = it.next(); ... } //#3 Iterator it = values.iterator(); while (it.hasNext()) { String value =

while loop won't terminate with a logical conditional

心已入冬 提交于 2019-12-04 06:21:11
问题 This loop won't terminate if I add an OR conditional statement. If one is false, then it should terminate. //global var int x = 100; char *n= malloc (64); void add(void) { do { printf("Would you like to add 1? (y/n) "); fgets(n, 64, stdin); //removes newline n[strlen(n)-1] = '\0'; x++; } //if I add || (x!=100) it keeps looping me even if I press "n" //otherwise without it it works fine while((strncmp(n, "n", 1) != 0) || x!=100 ); free(n); } 回答1: At the bottom of your loop, you're doing x++ .

python iterate though text file until condition is met

a 夏天 提交于 2019-12-04 06:10:32
问题 i would like to continue iterating through the text file until the current condition inside the loop is met. here is the sample text: 10-01 N/A 10-02 N/A 10-03 N/A 10-04 N/A 10-05 N/A 10-06 N/A 10-07 N/A 10-08 N/A 10-09 N/A 10-10 N/A 10-11 N/A 10-12 N/A ===04===...... # Skip line until '01' is found ===12===...... # Skip line until '01' is found 05-01 N/A 05-02 N/A 05-03 N/A 05-04 N/A 05-05 N/A 05-06 N/A ===08===...... # Skip line until '07' is found ===11===...... # Skip line until '07' is

Need to read white space and other chars C++

人盡茶涼 提交于 2019-12-04 06:10:19
问题 I have been working on this all day with no luck. Its night now and don't know what to do. My assignment is to read number of vowels, number of white spaces, and number of other characters in a user inputted sentence. I know i need to use cin.get(ch) for whitespaces, but don't know how. I also need to output the sentence to a file. Heres what I have so far: //Get data from user cout << "Enter your sentence on one line followed by a # to end it: " << endl; while (cin >> noskipws >> character &

How to run an sql query inside a while loop of another query

倾然丶 夕夏残阳落幕 提交于 2019-12-04 05:44:35
问题 The following works with no problem at all, when the photoId is directly on the statement and not a variable. $img_query = mysqli_query($con, 'SELECT * FROM imgs WHERE photoid = "103"') or die(mysqli_error($con)); but the following just won't work with no error, what might be causing this not to select. $imageid = '103'; $img_query = mysqli_query($con, 'SELECT * FROM imgs WHERE photoid = "$imageid"') or die(mysqli_error($con)); $img_row = mysqli_fetch_array($img_query); echo $img_row['img'];

float variable doesn't meet the conditions (C)

早过忘川 提交于 2019-12-04 05:04:46
问题 I'm trying to get the user to input a number between 1.00000 to 0.00001 while edges not included into a float variable. I can assume that the user isn't typing more than 5 numbers after the dot. now, here is what I have written: printf("Enter required Leibniz gap.(Between 0.00001 to 1.00000)\n"); scanf("%f", &gap); while ((gap < 0.00002) || (gap > 0.99999)) { printf("Enter required Leibniz gap.(Between 0.00001 to 1.00000)\n"); scanf("%f", &gap); } now, when I'm typing the smallest number

Grouping records from while loop | PHP

♀尐吖头ヾ 提交于 2019-12-04 04:43:44
问题 I'm trying to group down records by their priority levels, e.g. --- Priority: High --- Records... --- Priority: Medium --- Records... --- Priority: Low --- Records... Something like that, how do I do that in PHP? The while loop orders records by the priority column which has int value (high = 3, medium = 2, low = 1). e.g. WHERE priority = '1' The label: "Priority: [priority level]" has to be set above the grouped records regarding their level EDIT: <?php while($row = mysql_fetch_array($result