while-loop

PHP While loop displaying only last row

核能气质少年 提交于 2019-12-17 20:42:25
问题 I'm using TCPDF library to generate PDF of a table . Table has few number of rows say 10 Among that two rows has same invoice number "78650" Now i am selecting by invoice number and as desired it should generate PDF with two rows . But instead it is only fetching the second row that is the last row. That is Serial no 2 is only taken . Code Below : <?php require_once('TCPDF/tcpdf.php'); $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); $pdf-

Strange loop on Java for 0.1 to 2

末鹿安然 提交于 2019-12-17 20:32:30
问题 I tried to loop from 0.1 to 2.0 and then print the output to the console.. But I got strange output like these: 0.1 0.2 0.30000000000000004 0.4 0.5 0.6 0.7 0.7999999999999999 0.8999999999999999 0.9999999999999999 1.0999999999999999 1.2 1.3 1.4000000000000001 1.5000000000000002 1.6000000000000003 1.7000000000000004 1.8000000000000005 1.9000000000000006 2.0000000000000004 Source code: public class test { public static void main(String[] a) { double i = 0.1; while (i < 2.1) System.out.println(i)

Zend Studio reports warning: Assignment in condition. Is this so bad?

戏子无情 提交于 2019-12-17 20:07:22
问题 I have recently started using Zend Studio which has reported as warning the following type of code: $q = query("select * from some_table where some_condition"); while ($f = fetch($q)) { // some inner workings } To stop the warning the code needs to be written like this: $q = query("select * from some_table where some_condition"); $f = fetch($q); while ($f) { // some inner workings $f = fetch($q); } Why is this marked as a warning? Is it so bad? I understand that the warning may be designed to

Purpose of while(1); statement in C

試著忘記壹切 提交于 2019-12-17 17:38:20
问题 What purpose does while(1); serve ? I am aware while(1) (no semicolon) loops infinitely and is similar to a spinlock situation. However I do not see where while(1); could be used ? Sample code if(!condition) { while(1); } Note: This is not a case of do - while() or plain while(1) . 回答1: Please note that all valid statements of the language do not have to serve a purpose. They are valid per the grammar of the language. One can build many similar "useless" statements, such as if (1); . I see

In Javascript While loop repeats last number when counting from 1 to 5 when run on console [duplicate]

我与影子孤独终老i 提交于 2019-12-17 16:57:11
问题 This question already has answers here : Javascript while loop return value (3 answers) Closed 3 years ago . When running following code on console: var counter=0; while(counter<5){ console.log(counter); counter++; } console o\p: 0 1 2 3 4 4 whereas for following code works fine, without repeating last value: for(var i=0; i<5; i++){ console.log(i); } console o\p: 0 1 2 3 4 Now, if I place above for loop after above mentioned while loop , output is perfectly fine: var counter=0; while(counter

How to use feof(FILE *f)?

那年仲夏 提交于 2019-12-17 16:53:39
问题 I'm having a hard time with a do-while loop, that is supposed to stop when we reach the end of the file. Here's the loop code: do { if (pcompanyRow[0] != '#' && pass == 1) { strtok(pcompanyRow, ":"); pcompanyName = strcpy(pcompanyName, strtok(NULL, "")); pass = 2; fgets(pcompanyRow, 1024, f); } if (pcompanyRow[0] != '#' && pass == 2) { strtok(pcompanyRow, ":"); pcompanySMSPrice = strcpy(pcompanySMSPrice, strtok(NULL , "")); pass = 3; fgets(pcompanyRow, 1024 , f); } if (pcompanyRow[0] != '#' &

Why does an empty Java program consume memory?

走远了吗. 提交于 2019-12-17 16:12:14
问题 I'm exploring memory usage in Java to understand why my program leaks memory. After stripping off code in my main while loop, I still get an increase of memory usage over time. Pondering the memory usage of an empty program: class Nothing { public static void main(String[] args) { while(true); } } I still saw an increase of memory: So my question is: Why is there still a saw tooth pattern? Why when the GC runs does it not save all the memory (each time the gc runs (the valleys) the used

While or Tail Recursion in F#, what to use when?

混江龙づ霸主 提交于 2019-12-17 10:38:14
问题 Ok, only just in F# and this is how I understand it now : Some problems are recursive in nature (building or reading out a treestructure to name just one) and then you use recursion. In these cases you preferably use tail-recursion to give the stack a break Some languagues are pure functional, so you have to use recursion in stead of while-loops, even if the problem is not recursive in nature So my question : since F# also support the imperative paradigm, would you use tail recursion in F#

While or Tail Recursion in F#, what to use when?

让人想犯罪 __ 提交于 2019-12-17 10:38:00
问题 Ok, only just in F# and this is how I understand it now : Some problems are recursive in nature (building or reading out a treestructure to name just one) and then you use recursion. In these cases you preferably use tail-recursion to give the stack a break Some languagues are pure functional, so you have to use recursion in stead of while-loops, even if the problem is not recursive in nature So my question : since F# also support the imperative paradigm, would you use tail recursion in F#

How to use .nextInt() and hasNextInt() in a while loop

只愿长相守 提交于 2019-12-17 09:57:38
问题 So I want my program to read an input, which has some integers in one line, for example: 1 1 2 Then it should read every integer separately and print it in a new line. The number of integers the program has to read is not given in advance, so what I am trying to do is use a while loop, which ends after there are no more integers to read. This is the code I wrote: while (scan.hasNextInt()) { int x = scan.nextInt(); System.out.println(x); } but it's not working correctly, because the loop never