Query with a WHILE loop

DECLARE
@databasename AS
NVARCHAR(128);
SET
@databasename =
(SELECT
MIN(name)
FROM sys.databases
WHERE
name NOT
IN    ('master',
'model',
'msdb', 'tempdb'));
 WHILE
@databasename IS
NOT NULL BEGIN
PRINT @databasename;
SET @databasename
= (SELECT
MIN(name)
FROM sys.databases
        WHERE
name NOT
IN     ('master',
'model',
'msdb', 'tempdb')
        AND
name >
@databasename); END
Databases
A
B
C
D
I have question related to the above SQL statement, forgive me as I am unfamiliar with WHILE loops.
I understand that the query above finds the minimum database name, prints the value then finds the next database greater than the minimum.
What happens when it loops occurs,  I know it prints the database name of the one it has found.  In the example above it will be B.  Will the @databasename be then set to B and the following query will be run so the @databasename will then be
set to C?
 SELECT
MIN(name)
FROM sys.databases
        WHERE
name NOT
IN     ('master',
'model',
'msdb', 'tempdb')
        AND
name >
@databasename);

Yes. You run this query:
SET  @databasename =
   (SELECT MIN(name)
    FROM   sys.databases
    WHERE  name NOT IN    ('master','model', 'msdb', 'tempdb'));
This gives you the first user database, alphabetically according to your system database. The WHERE clause filters out the system databases.
Then in the WHILE loop you do the same, with one condition added:
     AND name > @databasename
So this gives the next user database alphabetically. But if there is no further database, the query returns NULL, and the condition in the WHILE statement will evaluate to FALSE, and the loop will terminate.
Erland Sommarskog, SQL Server MVP, [email protected]

Similar Messages

  • Can we execute a query in resultset while loop

    can we execute a query in resultset while loop
    for ex:
    rs=st.executeQuery("SQL");
    while(rs.next())
    rs1=st.executequery("SQL1");
    while(rs1.next())
    }

    If you do this, you lose "rs". Create a second
    Statement object for the other query.This is right. We have done it many times, It is not the issue as long as you use different statement with in the body of the loop

  • What's wrong with this while loop?

    Hi, folks. for the code fragment blow, resultSetArray holds two objects of type ResultSet. From those println statement, i can see the whole while loop(the most outter one) process goes alrite the first time right from begining to the end. However, when variable j increases from 0 to 1, the code stops executing at the the line while(rs.next). I just couldnt figure out what causes the problem while i've been fighting with it for several hours. Could someone plz throw me some lights? With your help, i could possibly go to bed before sun rises...
            while(j<resultSetArray.length)
              //for(int j=0; j<resultSetArray.length; j++)
    System.out.println("show me j is called twice " + j);
                   ResultSet rs = resultSetArray[j];
    System.out.println("the converting rs object is called twice and it is not null " + rs);
                  int numWantedColumns = wantedColumnNames.size();
                  //if it's about go or single trip
                  if(j==0 && rs != null)
                      go = new Element("Go");
                       //go.setText("go");
                       //result.addContent(go);
                  //if it's about return trip
                  else if(j==1 && rs != null)
                      back = new Element("Back");
                       //back.setText("back");
                       //result.addContent(back);
                  if(rs!= null)
    System.out.println("this hell is called twice coz it's not null");
                   while(rs.next())
    System.out.println("what about here?");
                        Element flightInfo = new Element("FlightInfo");
         System.out.println("while rs.next() is called");
                        for (int i = 0; i < numWantedColumns; i++)
                           String columnName   = (String)wantedColumnNames.get(i);
         System.out.println("column name is " + columnName);
                           String value = rs.getString(columnName);
          System.out.println("column value is " + value);
                           flightInfo.addContent(new Element(columnName).setText(value));
                        if(j==0)
                           go.addContent(flightInfo);
                        else if(j==1)
                             back.addContent(flightInfo);
                   else if(rs == null)
                        break;
                   j++;
             }

    i've got the problem sort out, eventually. there was actually nothing wrong with the while loop. it was caused by a typo in databse, instead of having Brisbane, i typed Bisbane. The single letter r cost me more than 6 hours to figure it out. it was such a painful feeling while i realized i made a such stupid mistake.
    by the way, as jnw777 mentioned, output rs.next() info instead of the test line. i did try it, however i didnt realize even System.out.println(rs.next()) would cause the cursor move down one row from its current position. so, plus the original while(rs.next()) statement, it was moving the cursor two rows down at a time! And i just couldnt think of this caused me the fact i was only getting the even number row of the ResultSet while i was sniffing the bug from a class with 700+ lines of code. I was so excited and just couldnt stop yelling at the moment i got over it! That was a damn execiting moment...
    now, i am wondering if anyone in this wonderland would like to share his/her stories.

  • Why the execution time increases with a while loop, but not with "Run continuously" ?

    Hi all,
    I have a serious time problem that I don't know how to solve because I don't know exactly where it comes from.
    I command two RF switches via a DAQ card (NI USB-6008). Only one position at the same time can be selected on each switch. Basically, the VI created for this functionnality (by a co-worker) resets all the DAQ outputs, and then activates the desired ones. It has three inputs, two simp0le string controls, and an array of cluster, which contains the list of all the outputs and some informations to know what is connected (specific to my application).
    I use this VI in a complex application, and I get some problems with the execution time, which increased each time I callled the VI, so I made a test VI (TimeTesting.vi) to figure out where the problem came from. In this special VI I record the execution time in a csv file to analyse then with excel.
    After several tests, I found that if I run this test VI with the while loop, the execution time increases at each cycle, but if I remove the while loop and use the "Run continuously" funtionnality, the execution time remains the same. In my top level application I have while loops and events, and so the execution time increases too.
    Could someone explain me why the execution time increases, and how can I avoid that? I attached my test VI and the necessary subVIs, as well as a picture of a graph which shows the execution time with a while loop and with the "run continuously".
    Thanks a lot for your help!
    Solved!
    Go to Solution.
    Attachments:
    TimeTesting.zip ‏70 KB
    Graph.PNG ‏20 KB

    jul7290 wrote:
    Thank you very much for your help! I added the "Clear task" vi and now it works properly.
    If you are still using the RUn Continuously you should stop. That is meant strictly for debugging. In fact, I can't even tell you the last time I ever used it. If you want your code to repeat you should use loops and control the behavior of the code.
    Mark Yedinak
    "Does anyone know where the love of God goes when the waves turn the minutes to hours?"
    Wreck of the Edmund Fitzgerald - Gordon Lightfoot

  • Slow performance of application with 2 while-loops

    I made an application with one while-loop addressing several FP devices which runs as expected in a FP-2015. Loop time is 100 ms.
    If I add another while-loop with a timer, the performance is very slow. How come?

    I tried to do a simular thing, but I did not notice a performance decrease. However it might be possible that this happens. For example, if you are calling a time critical vi in the second while loop, it will lock all other processes until it is finished. Or maybe you are calling a shared resource (allocate an array, access to a file, using a mutex) that the other loop holds. Until the shared resource is released the first while loop must wait before it can access that resource (memory, file, etc.).
    Without looking at the source code it will be hard to say what is causing it. I recommend to remove part by part subVI's from the second loop, to debug where the problem exists. If you want I can have a look at the code, please reply to this thread.
    ErikvH
    A
    pplications Engineering
    National Instruments
    Attachments:
    Digital_Output.vi ‏56 KB

  • The demand of my application is that i can not replace for loop with a while loop.because i need fixed number of iterations and as far as i know fixed iterations could be only with possible with the for loop.

    the demand of my application is that i can not replace for loop with a while loop.because i need fixed number of iterations and as far as i know fixed iterations could be only with possible with the for loop.
    your recommended second option that i could add true/false case.
    this true/false case must be inside the for loop or outside the for loop?if this case is inside the for
    loop, how can i send stop command from outer while
    loop?
    more over do you have any example for this please?
    thanks"

    You can execute a fixed number of iterations using a while loop by comparing the iteration count to the number of iterations you want and wiring the output of that comparison (e.g. Less Than or Equal To) to the continue (or stop) terminal of your while loop. Which comparison you use depends on personal preference, where you wire the desired count and the interation count, and whether you're using the while loop as Continue if True or Stop if True.
    Ben gave you step-by-step instructions in response to your previous question. Look here for Ben's response.
    Ben's response looks pretty good and detailed to me. It certa
    inly deserved better than a 1-star rating.

  • Problem with a while loop.

    I'm very new to java so please bear with me!!!
    This is my code:
    import java.io.*;
    public class IfExample2
        public static void main (String[] args) throws IOException
         // Read in a number
         BufferedReader br = new BufferedReader(
                         new InputStreamReader (System.in));
         System.out.print ("Enter a number between 0 and 10 inclusive: ");
         String temp = br.readLine();
         double x = Double.parseDouble(temp);
         // check user input
         if (x > 10)
             System.out.println("The number you entered is too high");
              System.out.println("Please re-enter the number");
         else if (x < 0)
             System.out.println("The number you entered is too low");
              System.out.println("Please re-enter the number");
         else
             System.out.println("The number you entered is " + x);
    }Basically I want, if the number entered is too high or too low I want it to ask the user to re-enter the number, I want to use a while loop but I'm not sure where or how to use it, please help!

    while ( condition ) {
        // stuff here
    }More on while: [http://java.sun.com/docs/books/tutorial/java/nutsandbolts/while.html|http://java.sun.com/docs/books/tutorial/java/nutsandbolts/while.html]
    Edited by: oscarjustesen on Oct 7, 2008 5:40 PM
    Edited - fixed link

  • Problems with a while loop within a method... (please help so I can sleep)

    Crud, I keep getting the wrong outputs for the reverseArray. I keep getting "9 7 5 7 9" instead of "9 7 5 3 1". Can you guys figure it out? T.I.A (been trying to figure this prog out for quite some time now)
    * AWT Sample application
    * @author Weili Guan
    * @version 1999999999.2541a 04/02/26
    public class ArrayMethods{
       private static int counter, counter2, ndx, checker, sum, a, size, zero;
       private static int length;
       private static int [] output2, output3, reverse, array;
       private static double output;
       private static double dblsum, dblchecker, average;
       public static void main(String[] args) {
          //int
          //int [] reverse;
          System.out.println("Testing with array with the values [1,3,5,7,9]");
          size = 5;
          array = new int [size];
          reverse = new int [size];
          array[0] = 1;
          array[1] = 3;
          array[2] = 5;
          array[3] = 7;
          array[4] = 9;
          System.out.println("Testing with sumArray...");
          output = sumArray(array);
          System.out.println("Sum of the array: " + sum);
          System.out.println();
          System.out.println("Testing with countArray...");
          output = countArray(array);
          System.out.println("Sum of the elements : " + checker);
          System.out.println();
          System.out.println("Testing with averageArray...");
          output = averageArray(array);
          System.out.println("The average of the array : " + average);
          System.out.println();
          System.out.println("Testing with reverseArray...");
          output2 = reverseArray(array);
          output3 = reverseArray(reverse);
          //System.out.print(reverse[4]);
          System.out.print("The reverse of the array : ");
          for(ndx = 0; ndx < array.length; ndx++){
             System.out.print(reverse[ndx] + " ");
       private ArrayMethods(){
       public static int sumArray(int[] array){
          checker = 0;
          ndx = 0;
          counter = 0;
          sum = 0;
          while(counter < array.length){
             if (array[ndx] > 0){
                checker++;
             counter++;
          if(array.length > 0 && checker == array.length){
             while(ndx < array.length){
                sum += array[ndx];
                ndx++;
             return sum;
          else{
             sum = 0;
             return sum;
        /*Computes the sum of the elements of an int array. A null input, or a
        zero-length array are summed to zero.
        Parameters:
            array - an array of ints to be summed.
        Returns:
            The sum of the elements.*/
       public static int countArray(int[] array){
          checker = 0;
          ndx = 0;
          counter = 0;
          sum = 0;
          while(counter < array.length){
             if(array[ndx] > 0 && array[ndx] != 0){
                checker++;
             counter++;
          return checker;
        /*Computes the count of elements in an int array. The count of a
        null reference is taken to be zero.
        Parameters:
            array - an array of ints to be counted.
        Returns:
            The count of the elements.*/
       public static double averageArray(int[] array){
          dblchecker = 0;
          ndx = 0;
          counter = 0;
          dblsum = 0;
          while(counter < array.length){
             if(array[ndx] > 0){
                dblchecker++;
             counter++;
          if(array.length > 0 && checker == array.length){
             while(ndx < array.length){
                dblsum += array[ndx];
                ndx++;
             average = dblsum / dblchecker;
             return (int) average;
          else{
             average = 0;
             return average;
        /*Computes the average of the elements of an int array. A null input,
        or a zero-length array are averaged to zero.
        Parameters:
            array - an array of ints to be averaged.
        Returns:
            The average of the elements.*/
       public static int[] reverseArray(int[] array){
          ndx = 0;
          counter = 0;
          counter2 = 0;
          if(array.length == 0){
             array[0] = 0;
             return array;
          else{
                //reverse = array;
             while(ndx <= size - 1){
                   reverse[ndx] = array[4 - counter];
                   counter++;
                   ndx++;
                   System.out.print("H ");
          return reverse;
        /*Returns a new array with the same elements as the input array, but
        in reversed order. In the event the input is a null reference, a
        null reference is returned. In the event the input is a zero-length array,
        the same reference is returned, rather than a new one.
        Parameters:
            array - an array of ints to be reversed.
        Returns:
            A reference to the new array.*/
    }

    What was the original question? I thought it was
    getting the desired output, " 9 7 5 3 1."
    He didn't ask for improving the while loop or the
    reverseArray method, did he?
    By removing "output3 = reverseArray(reverse):," you
    get the desired output.Okay, cranky-pants. Your solution provides the OP with the desired output. However, it only addresses the symptom rather than the underlying problem. If you'd bother yourself to look at the overall design, you might see that hard-coding magic numbers and returning static arrays as the result of reversing an array passed as an argument probably isn't such a great idea. That's why I attempted to help by providing a complete, working example of a method that "reverses" an int[].
    Removing everything and providing "System.out.println("9 7 5 3 1");" gets him the desired output as well, but (like your solution) does nothing to address the logic problems inherent in the method itself and the class as a whole.

  • BUG (?) with simple while loop in LV2011

    Hello all,
    I have found a very strange behaviour in LV2011: A While Loop is not executed when running as EXE (in Development Environment it works)
    While Loop:
    (OK, its not the best way to check if button was pressed, but the WHILE Loop itself should be executed)
    How to reproduce:
    1. download attached file
    2. open built EXE file
    3. Look at numeric indicator. At my PC, the values are not increased->this means: while loop is not running
    4. Open Project (lvproj)  (I hope I havent forgotten anything)
    5. Start running the VI from whithin LabView (debug) -> now it should run
    6. Try to build EXE
    7. Try with new EXE. Still not executed While Loop?
    BTW: I have saved the code for LV2010. There it is running. Strange.
    Thanks
    Eugen Wiebe
    Bernstein AG
    CLAD - Certified LabView Associate Developer
    Attachments:
    Project.zip ‏1253 KB

    Norbert_B wrote:
    I concur that this is unexpected behavior, but having dead code in the VI is always a bad idea.
    If this issue occurs with other code segments comparable to this (having dead code within case structures), i concur that it is a bug. ... 
    hope this helps,
    Norbert
    Hi Norbert,
    I'm hair-splitting as normal.
    Re Dead code
    Please cite a reference.
    1) There is an old school of thought that code should never be removed only replaced with a new version. This allows quickly switching back to the old version if the new version seems wacky.
    2) Diagram disable is new and we used to use a boolean to disable old code. Apperently there is some noob loose in R&D that never imagined anyone would use a constant and this bug fell through the testing cracks. I have recently logged a call >>> CAR about a case with a constant preventing a build.
    3) THe useage of a boolean constant to disable a code segment was knowan at one time becuase there was mutation code imlemented to convert constant to controls when open in a new version.
    4) A diagram disable will force an ignore of the code in the disabled state. A constant driven case did NOT have that behaviour and we used to use it to ensure dynamic VI's were included in VIs.
    So please cite the reference that I apperently missed.
    Ben
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • Help with a while loop condition

    I'm trying to write to a File. I ask the user for input, then I enter a while loop and test the condition. The loop works, but it won't stop. I've tried everything. Here is my code please help!!
    thanks
    inputline = keyboard.readLine();//read the keyboard
    try{
    while( inputline != null ){
    DiskOut.println( inputline );
    DiskOut.flush();
    inputline = keyboard.readLine();//read the keyboard again
    }//end while
    }//end try
    catch (IOException e) { 
    e.printStackTrace();
    }//end catch
    also i've tried these while loop conditions:
    while(inputline != "\n" || inputline != "\r") and the sort

    while(inputline != "\n" || inputline != "\r")The condition
    X!=Y OR X!=Z (given Y != Z)
    is always true. X will always not be equal to at least one of the values. So you'll want to use:
    while(!inputline.equals("\n") && !inputline.equals("\r"))In other words, "while inputline is not equal to either of them". Note the use of && instead of ||.
    If "keyboard" is simply a BufferedReader on top of System.in (and not your own class), the trailing line feeds and carriage returns won't even be in the string returned by readLine(). Your best bet is this:
    while(null != inputline && 0 != inputline.length())Make sure you type the two parts of that AND condition in the order above. If for whatever reason there are trailing \r and \n on the strings, you'll want to accomodate for platforms that may include both characters.
    // trim the trailing newline characters
    while(inputline.endsWith("\r") ||
          inputline.endsWith("\n")) {
       inputline = inputline.substring(0,inputline.length()-1);
    // or maybe this will work if you don't mind losing
    //  the whitespace at the beginning of the string:
    inputline = inputline.trim();Hope that helps somewhat.

  • Problem with Do-While Loop in a Binary Search

    The idea of the program is to randomly generate 10 integers, store them in an array then use a binary search to find the values at each position of the array in 10 or less steps.
    My problem is that the do-while loopisn't doing what it should be and I can't see the problem :S
    Thanks in advance.
    Se�n.
    int counter=0, guess=500, MIN=0, MAX=0;
    int arr[] = new int[10];
              for(int i=0; i<10; i++) {
          int ranNum= ( (int)(Math.random()*1000)+1 );
          arr=ranNum;
         System.out.println(ranNum);
         for(int j=0; j<10; j++) {
              do{
                   if(guess>arr[j]){
                        guess=MAX;
                        guess=guess/2;
                   else if(guess<arr[j]){
                        guess=MIN;
                        MAX=MIN*2;
    guess=((MAX-MIN)/2)+MIN;
                   else
                        guess=arr[j];
    }while(guess!=arr[j]);
              System.out.println("The number at position "+j+" in the array is :"+arr[j]);
    //resets the values each time the do-while loops breaks
              MIN=0;
              MAX=0;
              guess=500;

    Looks toe like MAX and MIN are always going to be zero.

  • Call a sub vi with a while loop in it

    hi..
    i have a code vi in which, there are cuple of ring controls and indicators...
    which are inter dependent based on selector values,and i used shift registers in while
    loop to see if the index of the ring controls are changed....
    now i woould like to this vi as a sub vi....where i am not able to get, control once the vi is called...if i replace a for loop instead
    of while loop ,the program behaves randomly......
    can anybody suggest me how do i call a sub vi aith a while loop in it.
    rags

    hi
    i have attcahed the the zip .vi.
    there are 2 ring controls....where in the values can be selected source res/source res2.
    the other 2 ring controls are indicators c current/c range.
    based on the selection there are 2 numeric indicators hidden and the
    range limit are set to the numeric controls clamp hi and clamp lo and a stop button
    to contol the loop.
    since changes are based on the ring controls, i am using shift registers
    to monitor the changes.
    if i want make this parth.vi as a sub vi and call it....due to while loop
    i am facinga problem...other than creating a global variable for
    stop button...can you thnk of any avenues.
    rags
    Attachments:
    partha.zip ‏86 KB

  • How do you prevent display glitches with multiple while loops.

    I would like to use 2 while loops, 1 for displaying elapsed time and the other for executing a sequence of initialization steps. Every time the sequence transistions from one frame to the next, I get a glitch in the elapsed time display. How can this be avoided? Should I be going about this in a different way?
    Attachments:
    timeTest.vi ‏265 KB

    I would drop the whole semaphore thing and hold the cluster in a functional global (also called a shift register database or LV2-style global, you can find info on the concept here). Add methods to update different parts of the cluster. Much easier code and the required protection of the cluster is there.
    MTO

  • How to find out how many recourds in recourd set  with out while loop

    hi
    i want to findout how many recourds in recourd set
    with out useing any loops like
    while(rs.next())
    count+=1;
    like this
    any mathod like(RecoundCount like )
    pls help me
    regards
    kedar

    If you dont want to use a scrollable result set do
    sql="SELECT COUNT(*) AS COUNT FROM TABLE"
    rs=stmt.executeQuery(sql);
    rs.next()
    count=rs.getString("COUNT");

  • Help with do while loop

      This program that reads a character representing a geometrical
      figure, then asks the user to enter the required data (ex. Radius for
      a circle, length and height for a rectangle, etc.  ...) .
      The program should then print the area and circumference.   Figures are: circle(c), square(s), rectangle(R), triangle (t).
      The program should repeat until a figure with area <10 are read
       import javax.swing.JOptionPane; // program uses class JOptionPane
        public class Sh7q6
       // main method begins execution of Java application
           public static void main( String args[] )
             String outputStr; // The output string
             String str; // The entered characher
             char n; // The character entered
                   double a; // aera
             double radius; // the radius of a circle
             double area; // the area of a circle, square, rectangle, triangle
             double circumference; // the circumference of a circle
             double m; // The square side length
             double circumference1;  //  the total for a * a
             double length;  // the length of a rectangle
             double width;  // the width of a rectangle
             double circumference2;  //  the total for 2*(length + width)
             double base; // the base of a triangle
             double side1; // the first side of a triangle
             double side2; // the second of a triangle
             double hight;
             double circumference3;  //  the total for ( base + side1 + side2 )
             do
             // display the information in a JOptionPane message dialog
                str = JOptionPane.showInputDialog("Enter a character specifying a geometrical shape" +
                   "\n" + " Circle = c" + "\n" + "Rectangle = R" + "\n" + "Square = s" + "\n"
                   + "Triangle = t" );
                n = str.charAt(0); // return the caracter
                switch (n)
                   case 'c':
                   case 'C':
                   // convert String inputs to double values for use in a calculation
                      radius = Double.parseDouble(
                         JOptionPane.showInputDialog("Enter the radius of a circle:"));     
                      area = 3.14 * Math.pow ( radius, 2); // calculate the area      
                      circumference = 2 * 3.14 * radius;// calculate the circumference
                      outputStr = String.format("The area of a circle is: %.2f%n" +
                         "The circumference of a circle is: %.2f", area, circumference);
                   // display result in a JOptionPane message dialog
                      JOptionPane.showMessageDialog(null, outputStr , "The result",
                         JOptionPane.INFORMATION_MESSAGE);
                      break;
                   case 's':
                   case 'S':
                   // convert String inputs to double values for use in a calculation
                      m = Double.parseDouble(
                         JOptionPane.showInputDialog("Enter the square side length:"));     
                      area = Math.pow ( m, 2); // calculate the area         
                      circumference1 = 4 * m;// calculate the circumference
                      outputStr = String.format("The area of a square is: %.2f%n" +
                         "The perimeter of a square is: %.2f", area, circumference1);
                   // display result in a JOptionPane message dialog
                      JOptionPane.showMessageDialog(null, outputStr , "The result",
                         JOptionPane.INFORMATION_MESSAGE);
                      break;
                   case 'r':
                   case 'R':
                   // convert String inputs to double values for use in a calculation
                      length = Double.parseDouble(
                         JOptionPane.showInputDialog("Enter the length of a rectangle:"));
                      width = Double.parseDouble(
                         JOptionPane.showInputDialog("Enter the width of a rectangle:"));     
                      area = length * width ; // calculate the area     
                      circumference2 = 2* (length + width); // calculate the circumference
                      outputStr = String.format("The area of a square is: %.2f%n" +
                         "The perimeter of a square is: %.2f", area, circumference2);
                   // display result in a JOptionPane message dialog
                      JOptionPane.showMessageDialog(null, outputStr , "The result",
                         JOptionPane.INFORMATION_MESSAGE);
                      break;
                   case 't':
                   case 'T':
                   // convert String inputs to double values for use in a calculation
                      base = Double.parseDouble(
                         JOptionPane.showInputDialog("Enter the base of a triangle:"));
                      side1 = Double.parseDouble(
                         JOptionPane.showInputDialog("Enter the first side of a triangle:"));
                      side2 = Double.parseDouble(
                         JOptionPane.showInputDialog("Enter the second side of a triangle:"));
                      hight = Double.parseDouble(
                         JOptionPane.showInputDialog("Enter the hight of a triangle:"));     
                      area = 0.5 * base * hight; // calculate the area      
                      circumference3 = base + side1 + side2;// calculate the circumference
                      outputStr = String.format("The area of a triangle is: %.2f%n" +
                         "The circumference of a yriangle is: %.2f", area, circumference3);
                   // display result in a JOptionPane message dialog
                      JOptionPane.showMessageDialog(null, outputStr , "The result",
                         JOptionPane.INFORMATION_MESSAGE);
                      break;
                   default:
                   // display result in a JOptionPane message dialog
                      JOptionPane.showMessageDialog(null, " The letter you entered doesn't " +
                         "represent either a circle or a rectangle or a square" , "ERROR",
                         JOptionPane.ERROR_MESSAGE);
             while (  area > 10 );
             System.exit(0);
          } // end method main
       } // end class Sh7q6the Q is how can i say when the area < 10 stop the loop in the while logical expression..

    the Q is how can i say when the area < 10 stop the loop in the while logical expression..You're almost already doing that. You're doing this:
             while (  area > 10 );As soon as the area is 10 or below, that expression will evaluate to false and the loop will end.
    If you want to still loop when the value is 10, then change it to:
             while (  area >= 10 );

Maybe you are looking for