While Loop Table

while loop in sql select statement
sql while loop through table rows
while loop in sql server stored procedure
sql while loop counter
insert data into table + using while loop
while loop in sql server for temp table
for loop in sql query example
sql for each loop

I need to make a table of Celsius to Fahrenheit conversions. The output should be exactly like this:

-40.0C  is  -40.0F  -30.0C  is  -22.0F  -20.0C  is  -4.0F   -10.0C  is  14.0F   
-39.0C  is  -38.2F  -29.0C  is  -20.2F  -19.0C  is  -2.2F   -9.0C  is  15.8F    
-38.0C  is  -36.4F  -28.0C  is  -18.4F  -18.0C  is  -0.4F   -8.0C  is  17.6F    
-37.0C  is  -34.6F  -27.0C  is  -16.6F  -17.0C  is  1.4F    -7.0C  is  19.4F    
-36.0C  is  -32.8F  -26.0C  is  -14.8F  -16.0C  is  3.2F    -6.0C  is  21.2F    
-35.0C  is  -31.0F  -25.0C  is  -13.0F  -15.0C  is  5.0F    -5.0C  is  23.0F    
-34.0C  is  -29.2F  -24.0C  is  -11.2F  -14.0C  is  6.8F    -4.0C  is  24.8F    
-33.0C  is  -27.4F  -23.0C  is  -9.4F   -13.0C  is  8.6F    -3.0C  is  26.6F    
-32.0C  is  -25.6F  -22.0C  is  -7.6F   -12.0C  is  10.4F   -2.0C  is  28.4F    
-31.0C  is  -23.8F  -21.0C  is  -5.8F   -11.0C  is  12.2F   -1.0C  is  30.2F    

The trick is, you can only use one while loop for the whole thing. Also you can't just type everything as it is. I am strugling to figure out a way for how to start a new column each time it goes through the 10 conversions or something of that type, i made a program that works but its lame and kinda cheating:

public class TempConvWorking{

public static void main (String[] args){

    double celsius1 = -40.0, celsius2 = -30.0, celsius3 = -20.0, celsius4 = -10.0;
    double fahreheit1, fahreheit2, fahreheit3, fahreheit4;

    while (celsius4 < 0){

        fahreheit1 = (celsius1 * (1.8) + 32.0);
        fahreheit2 = (celsius2 * (1.8) + 32.0);
        fahreheit3 = (celsius3 * (1.8) + 32.0);
        fahreheit4 = (celsius4 * (1.8) + 32.0);
        System.out.printf ("%.1fC  is  %.1fF\t%.1fC  is  %.1fF\t%.1fC  is  %.1fF\t%.1fC  is  %.1fF\t\n",celsius1,fahreheit1,celsius2,fahreheit2,celsius3,fahreheit3,celsius4,fahreheit4);
        celsius1 += 1;
        celsius2 += 1;
        celsius3 += 1;
        celsius4 += 1;

so if anyone has suggestions please explain.

I strongly suggest you create a method doing the conversion from Celcius to Fahrenheit and in addition print it. In my example I will use conv(double celcius) which prints for example "40.0C is -40.0F".

There's a pattern: the ten lines i0 until i9 each contain the conversions for -40 + i, -30 + i, -20 + i and -10 + i.

Within the while loop, you must call the conv method four times.

int i = 0;
while (i < 10) {
    conv(-40 + i);
    conv(-30 + i);
    conv(-20 + i);
    conv(-10 + i);
public static void conv(double celcius) {
    double fahrenheit = 1.8 * celsius + 32;
    System.out.printf("%.1fC  is  %.1fF\t" celcius, fahrenheit);

Reading table records through the WHILE loop. In the following example, we will read table data, row by row. Firstly we will create a sample table:  Usually cursors have less performance than an equivalent loop using a WHILE loop or CTE. Pros and Cons of Using a While Loop to Iterate Through Table Rows in SQL Server. There are also benefits to use a WHILE loop compared to a cursor. While loops are faster than cursors. While loops use less locks than cursors.

Assuming you want no counter variable outside the while loop and don't want to print more than one celsius-fahrenheit pair per iteration:

double celsius = -50.0;
double fahrenheit;

while (celsius < -1){

    if(celsius >= -10){
        celsius -= 39;
    celsius1 += 10;
    fahreheit = (celsius * (1.8) + 32.0);
    System.out.printf ("%.1fC  is  %.1fF\t",celsius, fahrenheit);

First off, you should learn the HTML code for tables. Your code is putting a Table Header ( th ) next to a normal column item ( td ). You need to  The while loop can also be used to implement paging. Paging refers to displaying a subset of records from a data table at any particular time. In the following script, the while loop will be used to select two records from the Cars table at a time.

Well, they're ten degrees off from each other, so you can eliminate several variables to simplify the code somewhat:

public class TempConvWorking {
  public static void main (String[] args) {
    double celsius = -40.0;
    while (celsius < -30.0) {
          "%.1fC  is  %.1fF\t%.1fC  is  %.1fF\t%.1fC  is  %.1fF\t%.1fC  is  %.1fF\t\n",
          1.8*celsius + 32.0,
          celsius + 10.0,
          1.8*celsius + 50.0,
          celsius + 20.0,
          1.8*celsius + 68.0,
          celsius + 30.0,
          1.8*celsius + 86.0);

This code produces the specified output.

Creating HTML tables using while loops in php. Loops can be used for all sorts of repetitive Duration: 9:47 Posted: Nov 9, 2012 DECLARE @id int SELECT @ID =1 WHILE @ID <= (SELECT MAX(ID) FROM table_1) -- while some condition is true, then do the following --actions between the BEGIN and END BEGIN UPDATE table_1 SET contact = CAST(siteID as varchar(100)) + contact WHERE table_1.CID = @ID --increment the step variable so that the condition will eventually be false SET @ID = @ID + 1 END --do something else once the condition is satisfied PRINT 'DONE!!

In this program the User asks to print a table with the use of while loop. While loop checks the condition at least once and after that it goes on. Three variables are  The while loop works like in any other programming language. It is an entry controlled loop and it is used to iterate the results. When we have tables with an identity column then it can be iterated.

Let's try to execute the while loop and iterate the table records one by one. DECLARE @totalRecords INT. DECLARE @I INT. SELECT @I = 1. The while loop requires relevant variables to be ready, in this example we need to define an indexing variable, i, which we set to 1. The break Statement. With the break statement we can stop the loop even if the while condition is true: Exit the loop when i is 3: Try it Yourself » The continue Statement. With the continue statement we can

Learn how to use a while loop in PHP in Tizag.com's PHP While Loops lesson. The loop created a new table row and its respective entries for each quantity,  Causes an exit from the innermost WHILE loop. Any statements that appear after the END keyword, marking the end of the loop, are executed. CONTINUE Causes the WHILE loop to restart, ignoring any statements after the CONTINUE keyword. Remarks. If two or more WHILE loops are nested, the inner BREAK exits to the next outermost loop.