while-loop

PHP - While / Else error? [closed]

爱⌒轻易说出口 提交于 2019-12-02 14:23:24
I have the following php code: <?php if (!isset($_REQUEST['search'])){ while(($write=mysql_fetch_array($gamesearched)) != null){ echo "Found!"; }else{ echo "No results"; } } ?> And it's giving me an error: Parse error: syntax error, unexpected 'else' (T_ELSE) in C:\php\www\Gameplay\backgame.php on line 41 jcsanyi In PHP, a while statement can't have an else clause. You need something external to the while that can tell you if it was executed at least once. How about something like this? $total = mysql_num_rows($gamesearched); if ($total > 0) { while (($write=mysql_fetch_array($gamesearched)) !

While loops, comparing more than one value

左心房为你撑大大i 提交于 2019-12-02 13:51:19
I can understand how to use the while loop perfectly if just to compare it with one thing, for example: x=int(input("Guess my number 1-10")) while x!=7: print("Wrong!") x=int(input("Try again: ")) print("Correct it is 7. ") However, if I want to compare two or more values through while loops (especially if I want to validate something), I would do something like this: number=input("Would you like to eat 1. cake 2. chocolate 3. sweets: ") while number!= "1" or number != "2" or number != "3": number=input("Please input a choice [1,2,3]") #Some code... When number does equal 1, 2 or 3, the

For Loop in JavaScript - Lottery Website

大城市里の小女人 提交于 2019-12-02 13:49:02
问题 I am trying to turn this code into a correct for loop statement, so that I can save my repetitions. I have tried my best to get it done, but I just don't know how I can write it correctly: function myProg() { var luckyNumber = 3; var luckyNumber2 = 5; var luckyNumber3 = 8; var firstInput = document.luckForm.numberBox.value; var secondInput = document.luckForm.numberBox2.value; var thirdInput = document.luckForm.numberBox3.value; var temp = ''; if (firstInput == luckyNumber && secondInput ==

While loop freezes game in Unity3D

余生颓废 提交于 2019-12-02 13:45:07
I've always struggled with while loops because they barely ever work for me. They always cause my Unity3D application to freeze, but in this instance I really need it to work: bool gameOver = false; bool spawned = false; float timer = 4f; void Update () { while (!gameOver) { if (!spawned) { //Do something } else if (timer >= 2.0f) { //Do something else } else { timer += Time.deltaTime; } } } Ideally, I want those if statements to run as the game runs. Right now it crashes the program and I know it's the while loop which is the problem because it freezes anytime I uncomment it out. Update() is

How can I create a loop for user input (until the user enters valid input)? [duplicate]

假装没事ソ 提交于 2019-12-02 13:42:09
This question already has an answer here: How to use Scanner to accept only valid int as input 6 answers My program should ask user to enter the amount they want to withdraw from their account and calculating the current balance after withdrawing. The requirement for withdrawing is minimum 100 and maximum 1000. If the user enters wrong input the program should re-promt and ask user to enter amount again. This process will keep repeating until the user puts right amount. Once the right amount is choosen it should calculate and display the current balance. This is how I tried, but I failed to

While loop user input in range

别等时光非礼了梦想. 提交于 2019-12-02 13:42:06
I have some code that I want to ask the user for a number between 1-100 and if they put a number between these it will print (Size: (input)) and break the loop, if however, they put in a number outside 1-100 it will print (Size: (input)), and proceed to re-ask them for a number, I have run into some problems though. c=100 while c<100: c=input("Size: ") if c == 1 or 2 or 3: print ("Size: "+c) break else: print ("Size: "+c) print ("Invalid input. Try again.") This should do it. c=input("Size: ") while int(c)>100 or int(c)<1: #Will repeat until the number is between 1 and 100, inclusively. #It

Help with PHP While function

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-02 13:32:44
Why is this not working? <?php $select = "select * from messages where user='$u'"; $query = mysqli_query($connect,$select) or die(mysqli_error($connect)); $row = mysqli_num_rows($query); $result = mysqli_fetch_assoc($query); $title = mysqli_real_escape_string($connect,trim($result['title'])); $message = mysqli_real_escape_string($connect,trim($result['message'])); while(($result = mysqli_fetch_assoc($query))){ echo $title; echo '<br/>'; echo '<br/>'; echo $message; } ?> where as this works - <?php echo $title; ?> SORRY TO SAY, BUT NONE OF THE ANSWERS WORK. ANY OTHER IDEAS? If your mysqli query

Multiple conditions in a while loop

僤鯓⒐⒋嵵緔 提交于 2019-12-02 13:28:29
问题 import java.util.Calendar; import java.util.GregorianCalendar; public class CountingSundays { public static void main(String args[]) { Calendar cal = new GregorianCalendar(1901, 00, 01); // month set to 0for jan , 1= feb etc while((cal.get(Calendar.YEAR) != 2001) && (cal.get(Calendar.MONTH) != 0) && cal.get(Calendar.DAY_OF_MONTH) != 1) { // while not 1/1/2001 System.out.print(cal.get(Calendar.MONTH)); // cal.add(Calendar.DAY_OF_MONTH, 1); } } } Im trying to iterate through the while loop by

While loop that is not working with Try/Catch statements

十年热恋 提交于 2019-12-02 13:26:43
问题 Im trying to give the user the opportunity to repeat an input after introducing something that has produced an error but something is not working because once the err is caught the try stuff is not executed again, instead it goes directly to the catch stuff generating an eternal cicle. Here is my code: while (err==1){ err=0; try{ dim = keyboard.nextInt(); } catch(Exception e){ System.out.println("Oops! What you entered is not an integer."); err=1; } } 回答1: When you enter a non-integer the

Infinite while nested in a for loop in matlab

℡╲_俬逩灬. 提交于 2019-12-02 13:19:13
I want to make a while loop, nested in a for loop in Matlab in order to find the distance between different pairs in the data. My data have the following form ID lon lat time 1 33.56 40.89 803 2 32.45 41.03 803 3 35.78 39.85 803 2 33.04 40.21 804 3 36.89 40.23 804 2 33.98 39.33 806 2 33.67 39.73 809 3 37.02 40.77 809 lon and lat are geographical coordinates. In the for loop, I want to take the first row from the matrix and then in the while loop check all other rows and compute the distance between the pairs as long as the condition in the while is true . What I mean is that for the first row