while-loop

Python While/For loop

浪尽此生 提交于 2019-12-12 06:59:29
问题 how can I make this into a while loop and output the same thing???? for x in range(56,120) : if (x < 57) : summation = 0 summation = x + summation if (x == 119) : print (“Sum of integers from 56 to 120 is”, summation) 回答1: summation = 0 start_val = 56 stop_val = 120 while start_val < stop_val: summation += start_val start_val += 1 print summation 回答2: There are various methods, but one of them is: x = 56 while x < 120: ... x += 1 回答3: sum = 0 x = 56 while x < 120: sum += x x += 1 print(sum)

Is something wrong in the while loop?

天大地大妈咪最大 提交于 2019-12-12 06:15:51
问题 I have a store_credits_orders table and orders table. The output that I want is similar to this but based on Store Credit Order Date and Time and Store Order Date and Time : The code that I have tried so far: <?php $table = ''; $queryToGetStoreCredit = "SELECT * FROM store_credits_orders WHERE SCO_CustEmailAdd = '".$_SESSION["Customer"]["email"]."'"; $validate->Query($queryToGetStoreCredit); if ($validate->NumRows() >= 1) { while ($rows_sco = $validate->FetchAllDatas()) { $used = $i = 0;

While loop with hasNext(); not fully looping

此生再无相见时 提交于 2019-12-12 06:08:24
问题 I'm in the process of creating a program that reads data from an external file, compares it with other data within the file then prints the results to a new external file. I am having problems with the while loop section of my code. I am unsure whether it is the while loop itself or the for loop which is nested within. Here is the code: public class WageCalculator { public static void main(String[] args) throws FileNotFoundException { Scanner input = new Scanner(new FileReader("TestData.txt")

While scanf EOF loop misbehaving

匆匆过客 提交于 2019-12-12 06:04:48
问题 I'm a beginner in C, and I've got problem I can't figure out, and wasn't able to find a solution on other threads here. I'm trying to read integers from a keyboard input/ txt file with the following code: int grades[MAX_GRADES_LENGTH]={0}, histogram[HISTOGRAM_SIZE]={0}; int maxGradesHistogramBucket=0, median=0, gradesLength=0; double avg=0.0; int grade=0; printf("Enter grades:\n"); while (scanf("%d",&grade) != EOF) { grades[gradesLength]=grade; gradesLength=gradesLength+1; } I'm supposed to

PHP Mysql WHILE loop remove the last separator

a 夏天 提交于 2019-12-12 05:49:50
问题 I have this code that get the data from mysql database. <?php $sql = mysql_query( "SELECT * FROM users WHERE name = $name" ); while ( $row = mysql_fetch_array( $sql ) ) { echo $row[id] . '|'; echo $row[name] . '|'; echo $row[add] . ':'; } OUTPUT : 12|jonathan|philippines:14|John|england: ?> How can I remove the last separator of : using while? 回答1: $sql = mysql_query( "SELECT `id`, `name`, `add` FROM users WHERE name = $name" ); $data = array(); while ( $row = mysql_fetch_array( $sql, MYSQL

Find longest repeating string based on input in perl (using subroutines)

ぃ、小莉子 提交于 2019-12-12 05:49:25
问题 So I'm trying to find the longest repeat for a specific pattern thats given. My code so far looks like this, and is fairly close, however it does not fully give the wanted result: use warnings; use strict; my $DNA; $DNA = "ATATCCCACTGTAGATAGATAGAATATATATATATCCCAGCT" ; print "$DNA\n" ; print "The longest AT repeat is " . longestRepeat($DNA, "AT") . "\n" ; print "The longest TAGA repeat is " . longestRepeat($DNA, "TAGA") . "\n" ; print "The longest C repeat is " . longestRepeat($DNA, "C") . "\n

While Loop Fail - Caesar Cipher

风格不统一 提交于 2019-12-12 05:27:57
问题 I'm having a problem where when I ask my program to quit out it prints like I ask it to, however shows my menu of options as well continuously. So I'm getting this: >>> (S)huffle a message. (U)nshuffle a message. (Q)uit program. Choose a option to begin: q Goodbye! (S)huffle a message. (U)nshuffle a message. (Q)uit program. Choose a option to continue: Where I want it to display this if I choose 'q': >>> (S)huffle a message. (U)nshuffle a message. (Q)uit program. Choose a option to begin: q

Update rows in a while loop php

喜你入骨 提交于 2019-12-12 05:27:45
问题 I have a working mail script and there are times that the sending times out because our internet connection is not stable. I was advised to mark sent messages to the mails after it has been sent. I've tried this script but so far it only updates the first email it sends to and not the rest. if(isset($row_get_sender['setfrom_email'])) { do { $mail->AddAddress($row_get_recipient['email']); $mail->Send(); $update_recipient; $mail->ClearAddresses(); } while($row_get_recipient = mysql_fetch_assoc(

Update echoed data using WHILE loop. Only updates one record

馋奶兔 提交于 2019-12-12 05:18:05
问题 I can't seem to be able to update any records except the first one. I am not sure how to modify any of the displayed records. <?php if(isset($_POST["action"]) == "update") { $id = $_POST['m_id'][0]; $type = $_POST['type'][0]; // if I echo $id & $type, it only gives me the first record.** mysql_query(" UPDATE membership_type SET mt_type ='$type' WHERE mt_id = '$id'" ); } ?> ALl of this is within the same php page. <form name=form action='' method='post'> <?php $result=mysql_query("SELECT *

How do I create a while loop around a for loop that will allow the user to quit the loop?

喜夏-厌秋 提交于 2019-12-12 05:16:52
问题 I am new to loops and I coded a for loop already that prompts the user to input a phrase and the for loop prints out how many spaces, a's, e's ,s's, and t's there are. I need to make a while loop that will allow the user to type in "quit" to quit the loop. I am also new to learning switch to print out the letters. I have already tried experimenting with my code to fix my errors (either an ongoing loop or no results) for over a week. Here is my code below and thank you in advance. import java