while-loop

how to use one query for two loops

て烟熏妆下的殇ゞ 提交于 2020-01-14 04:13:09
问题 how can i write query in this situation: this is the query $gdQuery = $conn->query("blah blah "); i want to use the above query for while loop that is two time. is to retrive skillname (name) is to retrivestudent name (student_fname) is it a correct approach if not how can i do that..? <table> <thead> <th>Paricipant</th> <?php while($gdData = $gdQuery->fetch_assoc()) { ?> <th class="text-center"><?php echo $gdData['name']; ?></th> <?php } ?> <th>Score</th> </thead> <tbody> <tr> <?php while(

Variable initalisation in while loop

纵然是瞬间 提交于 2020-01-13 10:19:09
问题 I have a function that reads a file in chunks. public static DataObject ReadNextFile(){ ...} And dataobject looks like this: public DataObject { public string Category { get; set; } // And other members ... } What I want to do is the following basically List<DataObject> dataObjects = new List<DataObject>(); while(ReadNextFile().Category == "category") { dataObjects.Add(^^^^^ the thingy in the while); } I know it's probably not how it's done, because how do I access the object I've just read.

How is “0” result from readdir() not false in a while condition?

陌路散爱 提交于 2020-01-13 09:36:10
问题 See also: Where in the documentation does it say that while tests readdir for definedness?. ( Not a duplicate; just closely related. ) Many people treat the loop below as idiomatic: while (defined(my $file = readdir($dir)) { ... } instead of: while (my $file = readdir($dir)) { ... } because supposedly with the latter version if the filename is just "0" (zero) it should terminate the loop, whereas it returns 'undef' when there are no more files. However at some point in the past this test for

Does while loop have two Arguments?

我只是一个虾纸丫 提交于 2020-01-13 06:12:35
问题 My ma'am gave me one question to solve. To predict the output of the following code. #include <stdio.h> int main() { int i = 0, j = 0; printf("Output is : "); while (i < 5, j < 10) // Doubt: how does while accept 2 arguments?? and how it works?? { i++; j++; } printf("%d, %d\n", i, j); } I thought it was a syntax error. But when I tried to run, it gave me output. Output is : 10, 10 But How? Can anyone explain? But if I remove the first printf statement printf("Output is : "); and run it, my

Accessing datetime.now() values in Python

不问归期 提交于 2020-01-13 05:25:07
问题 I want to be able to implement a condition in my program where it would only run for N number of hours, maybe the user could specify N, but let's not jump ahead. I figured I could use datetime.now() and store the value below in a variable, time >>> time >>> time = datetime.datetime(2013, 12, 9, 21, 50, 32, 405329) Any ideas on how I can access the fourth field between the (--), seeing as it's a string? My condition would be something like while time != timeEnd where timeEnd would be the value

What condition does while(true) test? When is it true and false?

扶醉桌前 提交于 2020-01-12 06:21:29
问题 I do no understand why anybody would use while(true) { //do something } instead of boolean condition = true; while(condition == true) { //do something } The latter is super easy to understand, whilst the former is not. So, what condition does while(true) check? When is while(true) true, and when is it false? 回答1: When is while(true) true, and when is it false? It's always true, it's never false. Some people use while(true) loops and then use break to exit them when a certain condition is true

How to insert name field in mailx

ぐ巨炮叔叔 提交于 2020-01-11 14:43:28
问题 My sample data File is $ cat /fullpath/myfile.csv a@gmail.com, A Singh k@gmail.com, K Singh I am using script.sh #!/bin/bash while IFS= read -r line do email=$(echo $line | awk -F, '{print $1 }') name=$(echo $line | awk -F, '{print $2 }') echo | mailx -v -s "Helo $name" -S smtp-use-starttls -S ssl-verify=ignore -S smtp-auth=login -S smtp=smtp://smtp.gmail.com:587 -S from="xxxx@gmail.com(John Smith)" -S smtp-auth-user=xxxx@gmail.com -S smtp-auth-password=xxxxpassword -S ssl-verify=ignore -S

How would I use a while loop to keep requesting user input

╄→尐↘猪︶ㄣ 提交于 2020-01-11 13:09:35
问题 I've tried a couple of things with the while loop and can't seem to get it to work. I want to keep requesting user input until the user inputs the number 0, here is the code I have so far: import java.util.*; public class Task10 { public static void main(String[] args) { System.out.println("Enter a year to check if it is a leap year"); Scanner input = new Scanner(System.in); int year = input.nextInt(); if ((year % 4 == 0) || ((year % 400 == 0) && (year % 100 != 0))) System.out.println(year +

Reading input using Scanner causes an infinite loop in Java [duplicate]

假装没事ソ 提交于 2020-01-11 12:48:32
问题 This question already has answers here : How to handle infinite loop caused by invalid input (InputMismatchException) using Scanner (5 answers) Closed 2 years ago . In my program I'm trying to get a user to input an int between 1-3 and then do something based off what they type. If it is not a number or not one of the options then it will allow them to reenter a valid option. The issue I have is I'm having trouble brainstorming how to not have it infinitely loop and just allow them to enter

Java - How to break out of while with hasNext() condition?

戏子无情 提交于 2020-01-11 11:38:11
问题 I am writing a simple program to calculate the average of a set of numbers. You get the numbers using Scanner , so I am using while loop with .hasNext() as a condition. However the loop is infinite. Is it possible to break out of it without writing some certain word like "stop" in the input? public class main { public static void main(String[] args){ Scanner Input = new Scanner(System.in); int count = 0; int temp; int sum = 0; while(Input.hasNextInt()){ count++; temp = Input.nextInt(); sum +=