Help with my nested loop...

this application allows a user to enter two int values, rows(height) and columns(length), that are used to create a box of asterisks.
my createBox() does not work correctly, only prints first line, loops infinitely, or doesnt loop. can someone help me out please?
import java.io.*;
public final class AsteriskBox
/****InstanceVariables****/
public static int row;
public static int col;
/****Constructor()****/
public AsteriskBox()
/****Access()'s****/
public void createBox(int x, int y)
if((x > 0) && (y > 0))
for(int i = x; i > 0; i--)
for(i = y; i > 0; i--)
System.out.print("*");
System.out.println();
} // createBox()
public void getInput() throws IOException
BufferedReader input = new BufferedReader
(new InputStreamReader(System.in));
System.out.print("Enter a number of rows: ");
String inputString = input.readLine();
row = convertStringToInteger(inputString);
System.out.print("Enter a number of columns: ");
inputString = input.readLine();
col = convertStringToInteger(inputString);
} // getInput()
/****Helper()****/
private int convertStringToInteger(String s)
Integer intObject = Integer.valueOf(s);
return intObject.intValue();
} // convertStringToInt()
} // AsteriskBox class
import java.io.*;
public class AsteriskBoxUser
public static void main(String args[]) throws IOException
AsteriskBox box = new AsteriskBox();
System.out.println("This program creates a box made of asterisks with values given by you!");
System.out.println();
box.getInput();
box.createBox(AsteriskBox.row, AsteriskBox.col);
}

You will never break out of the first loop because you are using the same index variable i for both of your nested loops. Use a different variable, say j for your inner loop.
Incidentally, your row and col variables are mislabeled. If you use the static modifier, they are class variables, not instance variables. This could cost you points on your assignment since it would imply that you don't know the difference.

Similar Messages

  • Help with a nested loop

    basically i need to make a diamond shape out of asterisks. There should be 11 in the middle and decreasing by 2 each line above and below it, until it reaches 1. Now i've come up with a for loop that prints what i need for the top half of the diamond(but the asterisks are not centered). How would i center them and also print the bottom half of the diamond? here's what i have so far.
    import java.io.*;
    class diamond{
         public static void main(String[] args)
         int a;
         int b;
              for(a = 1; a <=11; a++)
                   for(b = 1; b <= a; b++)
                        System.out.print('*');
              System.out.println();
    }here's what it outputs:
    Press any key to continue . . .

    public class Diamond {
        private static final int MAX = 11;
        private static final int MIN = 1;
        public static void main(String[] args) throws Exception {
            for(int a = MIN; a <= MAX; a++) {
                for(int b = MAX; b >= MIN; b--) {
                    if(b <= a) {
                        System.out.print(" *");
                    } else {
                        System.out.print(" ");
                System.out.println();
            for(int a = MIN; a <= MAX; a++) {
                for(int b = MIN; b <= MAX; b++) {
                    if(b <= a) {
                        System.out.print(" ");
                    } else {
                        System.out.print(" *");
                System.out.println();
    }And here's my output:
               *

  • I need help with my for loop in this array

    Ok well, I can't get my code to work. Also, please remember that this is just my draft so it isnt pretty. I will fix it up later so please look at it. The thing I want to do is look into the array for a time that matches what the user entered and return the toString() of that one. I know there is something wrong with my for loop but I cant figure how to fix it. please help. here is what i have so far:
    import javax.swing.JOptionPane;
    public class Runner
        public static void main (String[] args)
            String timeStr;
            int time, again, optiStr;
            Inbound[] in = new Inbound[25];
             in[0]=new Inbound ("",0,"On Time num0");
             in[1]=new Inbound ("",2,"On Time num1");
             in[2]=new Inbound ("",3,"Delayed num2");
             in[3]=new Inbound ("",4,"On Time");
             in[4]=new Inbound ("",5,"On Time");
             in[5]=new Inbound ("",6,"Canceled");
             in[6]=new Inbound ("",1,"Canceled num6");
             in[7]=new Inbound ("",8,"On Time");
             in[8]=new Inbound ("",9,"Delayed");
             in[9]=new Inbound ("",10,"On Time");
             in[10]=new Inbound ("",11,"Delayed");
             in[11]=new Inbound ("",12,"On Time");
             in[12]=new Inbound ("",13,"Delayed");
             in[13]=new Inbound ("",14,"On Time");
             in[14]=new Inbound ("",15,"On Time");
             in[15]=new Inbound ("",16,"On Time");
             in[16]=new Inbound ("",17,"Canceled");
             in[17]=new Inbound ("",18,"On Time");
             in[18]=new Inbound ("",19,"On Time");
             in[19]=new Inbound ("",20,"Canceled");
             in[20]=new Inbound ("",21,"On Time");
             in[21]=new Inbound ("",22,"Delayed");
             in[22]=new Inbound ("",23,"On Time");
             in[23]=new Inbound ("",24,"Cancled");
             in[24]=new Inbound ("",7,"On Time num24");
            do{
                timeStr = JOptionPane.showInputDialog ("In military time, what hour do you want?");
                time = Integer.parseInt(timeStr);
                if (time<=0 || time>24)
                 JOptionPane.showMessageDialog (null, "Error");
                 optiStr = JOptionPane.showConfirmDialog (null, "If you want Incoming flights click Yes, but if not click No");
                if (optiStr==JOptionPane.YES_OPTION)
    //(ok this is the for loop i am talking about )
                    for (int index = 0; index < in.length; index++)
                      if ( time == Inbound.getTime())
                   JOptionPane.showMessageDialog (null, Inbound.tostring());  //return the time asked for
    //               else JOptionPane.showMessageDialog (null, "else");
                }//temp return else if failed to find time asked for
    //             else
    //               if (optiStr==JOptionPane.CANCEL_OPTION)
    //                 JOptionPane.showMessageDialog(null,"Canceled");
    //              else
    //                {Outbound.run();
    //                JOptionPane.showMessageDialog (null, "outbound");}//temp
                  again=JOptionPane.showConfirmDialog(null, "Try again?");
            while (again==JOptionPane.YES_OPTION);
    }any help would be greatly appriciated.

    rumble14 wrote:
    Ok well, I can't get my code to work. Also, please remember that this is just my draft so it isnt pretty. I will fix it up later so please look at it. The thing I want to do is look into the array for a time that matches what the user entered and return the toString() of that one. I know there is something wrong with my for loop but I cant figure how to fix it. please help. here is what i have so far:
    >//(ok this is the for loop i am talking about )
    for (int index = 0; index < in.length; index++)
    if ( time == Inbound.getTime())
    JOptionPane.showMessageDialog (null, Inbound.tostring());  //return the time asked for
    Inbound.getTime() is a static method of your Inbound class, that always returns the same value, I presume? As opposed to each of the 25 members of your array in, which have individual values?
    Edited by: darb on Mar 26, 2008 11:12 AM

  • Help with corrupted nested sequences.

    First off, let me say that next project I'm going with Avid. 
    I have been using nested sequences as sparingly as possible on a long, complicated project, but the few that I have are prone to getting "corrupted" (this is the technical  term that Kevin Monahan from Adobe has used to describe what's happening).  So it's been recommended that I replace the corrupted sequence.  Sure I can just copy the material in the corrupted sequence and place it in a new sequence, but how can I do this without loosing my HOURS of edits with this nested sequence in my main timeline?
    Thanks,
    Steve Keller

    Have you got a backup of your original photos?  If so then you can
    recreate the catalogue very easily in less than 5 minutes.  PSE always
    leaves photos in their original location.  they are not moved at all. 
    One should always backup photos, videos, documents, emails etc
    separately from applications that created them in the first place. 
    Disasters happen and we can't always protect from them except to backup
    as taught in computing 101 class.

  • ABAP help with deeply nested items.

    Gurus,
    We have a requirement whence we need to sum up the key figures from one transformation layer going to the next.  The challenge is, its a deeply nested structure. something like :
    SalesOrderItem     Higher Level Item         KeyFig  
    1000                     0000                          30
    1010                     1000                          20
    1011                     1010                          10
    1015                     1010                          20
    1020                     1010                          20
    1021                     1020                          10
    1022                     1020                          50
    1023                     1020                          10
    1025                     1020                          20
    So now, in the next layer we will be rolling it upto the 1000 , 2000...levels- in this example 1000 level only.
    The round figure items(1010, 1020.....) are the individual kmats and the summation happens like this:
    1. Items 1021, 1022, 1023 and 1025 roll up to 1020; sum = 90.
    2. Now when 1020 rolls up to its higher level item which is 1010, the sum that rolls up from 1020 should be 90 + 20.
    3. Ultimately when all items roll up to item 1000, the total sum will be 190.
    Can someone please help me write this logic in ABAP?
    Thanks!
    Chris

    You can try this, but please put it through more examples. Assumption is that your highest level item will have higher item number as 0000 and that they are always sorted in the way it is given in your example.
    DATA: BEGIN OF itab OCCURS 0,
            posnr(6) TYPE n,
            uposn(6) TYPE n,
            qty TYPE p DECIMALS 2.
    DATA: END OF itab.
    DATA: itab2 LIKE itab OCCURS 0 WITH HEADER LINE.
    DATA: itab3 LIKE itab OCCURS 0 WITH HEADER LINE.
    DATA: v_total TYPE p DECIMALS 2,
          v_posnr(6) TYPE n.
    itab-posnr = '1000'.
    itab-uposn = '0000'.
    itab-qty   = 30.
    APPEND itab.
    itab-posnr = '1010'.
    itab-uposn = '1000'.
    itab-qty   = 20.
    APPEND itab.
    itab-posnr = '1011'.
    itab-uposn = '1010'.
    itab-qty   = 10.
    APPEND itab.
    itab-posnr = '1015'.
    itab-uposn = '1010'.
    itab-qty   = 20.
    APPEND itab.
    itab-posnr = '1020'.
    itab-uposn = '1010'.
    itab-qty   = 20.
    APPEND itab.
    itab-posnr = '1021'.
    itab-uposn = '1020'.
    itab-qty   = 10.
    APPEND itab.
    itab-posnr = '1022'.
    itab-uposn = '1020'.
    itab-qty   = 50.
    APPEND itab.
    itab-posnr = '1023'.
    itab-uposn = '1020'.
    itab-qty   = 10.
    APPEND itab.
    itab-posnr = '1025'.
    itab-uposn = '1020'.
    itab-qty   = 20.
    APPEND itab.
    itab2[] = itab[].
    *-- assumption is that if UPOSN = 000000, then there is no higher level
    *   item
    LOOP AT itab WHERE uposn = '000000'.
      itab3-posnr = v_posnr = itab-posnr.
      DO.
        LOOP AT itab2 WHERE uposn = v_posnr.
          v_total = v_total + itab2-qty.
        ENDLOOP.
        IF sy-subrc <> 0.
          EXIT.
        ELSE.
          v_posnr = itab2-posnr.
        ENDIF.
    *-- This item does not appear as a higher level item
      ENDDO.
      v_total = v_total + itab-qty.
      itab3-qty = v_total.
      APPEND itab3.
      CLEAR itab3.
    ENDLOOP.
    LOOP AT itab3.
      WRITE:/ itab3-posnr,
              itab3-qty.
    ENDLOOP.

  • Need help with the for loop

    Hello,
    I hope someone can point me in the right direction for my next assignment. I am very new at Java programming. For my next assignment for class I will need expand my previous program which was a mortgage calculator. The first assignment we wrote a program to show the monthly payments of a $200,000 loan at 5.75% for 30 years. Now we have to output all 360 monthly payments with pauses in between so it doesnt scoll off the page. The calculation that we use is:
    month_payments = (principle * monthlyinterest) / (1-Math.pow(1 + monthlyinterest, - months));
    My question is how do I get the correct calculation outputed 360 times. I would like to use the "for loop" to do this. Also what is the correct way to do the pause command? I do not want someone to write the code, I just want some help to where I need to start off, I want to learn this on my own.
    Thanks in advance,
    DC

    for (int i ; i < 10 ; i ++ ) { System.out.println("Come sail away"); }
    or;
    int i = 0;
    while(i < 10)
        i++;
        System.out.println("Come sail away");
    }

  • Need help with basic "for" loops!

    Here is my prompt for class:
    Write a program that prompts the user to enter a sentence from the keyboard using JOptionPane.showInputDialog.
    The program will print the characters back with the first letter of each word changed from lower case into upper case. If you have a capital letter in the original line and it is not the first letter of a word, then this letter should be switched from upper case to lower case. The only capital letters that should appear in the line must be the beginning letter of every word in the line. All other characters will remain the same.
    I figured everything out except for one part. How do I make the first letter of each word change from lower case into uppercase? How do I switch a letter that is uppercase in the middle of a word to lowercase? Last but not least, how do I make sure that the only capital letters in the sentence are the first letter of each word?
    I need to do this using for Loops, charAt(), and if/else statements because this is just an intro class. I just can't figure this last part out! Help please!

    String words = ...;
    StringBuilder builder = new StringBuilder();
    for (int i = 0; i < words.length; i++) {
    char c = words.charAt(i);
    boolean isUpper = Character.?(look up the methods in java.lang.Character)
    boolean isLetter = ? (there are actually 2 ways to do this. Hint: you can use <= and >= and && to solve this)
    if (!isLetter) {
    continue;
    } else {
    // check if this is the start of the word. How do you know that you are at the start of a word?
    if (!isUpper && isStartOfTheWord) c = Character.toUpperCase(c); //Hint: there is a way you can do this with x + y
    else if (isUpper) //make c lower case
    builder.append(c);
    return builder.toString();

  • Need help with an infinite loop please

    Can somebody please help me out with displaying text that's been imported from another file onto a JTextArea? this is the code i've been trying to get to work, and it does, but it is stuck in an infinite loop and i can't see why. I've tried adding a counter before the while loop, and displaying and incrementing it inside the loop. The counter gets to 32 (the last line of the file) then goes back to 1 and starts again. Any help, or explanations would be awesome, thanks.
    String line;
         while ((line=reader.readLine())!=null){
              System.out.println(num);
              append(line+" \n");
         }                              

    think you will have to post some more of the code, is that within any sort of loop itself , has it its own method ? is it an event handler ? ..btw the append sould be fine .. is this a subclass of a TextArea ? where is this bit of code ?
    Message was edited by:
    odd_function

  • Help with these two loops

    Hi I hope someone can help me?
    I have these two loops, which at the moment prints out like this
    addr1, id, phone, lastname, firstname
    town, addr2, postcode, county, country
    [7,4,2,1,0]
    [9,8,6,5,3]
    the first two lines is what vector vv2 holds inside it.
    the second two line is what vector vv holds inside it.
    my problem is how can i get it to printout like this?
    [7,4,2,1,0]
    addr1, id, phone, lastname, firstname
    [9,8,6,5,3]
    town, addr2, postcode, county, country
    I hope someone can help me thanks
    nicky
    for (int ii2=0;ii2 < results2.size(); ii2++) {
                    vv2 = (Vector)results2.elementAt(ii2);     
                          ste2 = vv2.toString();
                             stb2 = new StringBuffer(ste2);
                             stb12 = new StringBuffer();
                             int is = stb2.length();
                             int is2 = is-2;
                             int is3 = is-1;
                             stb2.replace(0,1,"");
                             stb2.replace(is2,is3,"");
                             for(int i222 = 0; i222 < vv2.size(); i222++){
                                  stb12.append(",");
                                  stb12.append("?");
                                  stb12.replace(0,1,"");
                                  System.out.println(stb2);
    for (int ii = 0; ii < results.size(); ii++) {
        vv = (Vector)results.get(ii);
    System.out.println(vv);
    }

    You are using more for loops than you need to. If you just want to print out the element of one vector after the other then just put it in the same loop. Here try this:
    for (int ii2=0;ii2 < results2.size(); ii2++) {
                    vv2 = (Vector)results2.elementAt(ii2);     
                          ste2 = vv2.toString();
                             stb2 = new StringBuffer(ste2);
                             stb12 = new StringBuffer();
                             int is = stb2.length();
                             int is2 = is-2;
                             int is3 = is-1;
                             stb2.replace(0,1,"");
                             stb2.replace(is2,is3,"");
                             for(int i222 = 0; i222 < vv2.size(); i222++){
                                  stb12.append(",");
                                  stb12.append("?");
                                  stb12.replace(0,1,"");
                                  System.out.println(stb2);
         vv = (Vector)results.get(ii2);
         System.out.println(vv);
          And for god sakes man use some better names for your for loop iterator. Usually it is custom to start with i and if you need an inner for loop or another for loop within the same scope move on to using j and then k, so on and so on. All those numbers in your variables make the code harder to read than it needs to be. Just a suggestion, good luck.

  • Help with XML Nested sets

    I'm currently making a table similar to the Product Table on
    the Spry demo. I'm having some problems because I need to link
    videos and sounds from nested XML categories to a sidebar, similar
    to the features list on the demo site. The problem is, I dont want
    the full URL to show, but something else
    I managed to get the list to show what I wanted by doing
    something like this:
    <media>
    <video>2004/videos/x.mov <name>Great Video
    </name> </video>
    </media>
    By calling spry:region="media" and then
    <ul><li><a
    href={video}>{name}</a><li></ul>
    I got a full list with the names, but the links were
    apparently lost, and all pointed to the table's url.
    I also tried doing a <div spry:region="media"
    spry:region="name"> and list the <video> and <name>
    tags separately on the XML, but that didn't work.
    I'd be very greatful if someone could help me figure out how
    to do this.
    Thank you,
    Jose

    Just looking at your post, I noticed that when you put the ibar in your shelf and add applications the icons don't like to show up you have to
    1. right click on the application in the ibar
    2. select icon program-properties-icon
    3.click on the grey box
    4.navigate to /usr/share/icons/highcoler/64x64/apps  (you can select 48x48 as well)
    The icon should show up in ibar, as well as the applcation menu. It is hit and miss though. I hope this helps.
    Edit: I think I solved the hit and miss attribute, instead of selecting the file in the middle of the window manager select it to the right. And make sure that the file shows up in the bar at the bottom of the filemanager window.
    Last edited by mich04 (2012-11-25 13:40:36)

  • Help with resultset and looping thru a sql filed

    Hi,
    I have a SQL statement which connects two tables with accounting number, the table2 have multiple rows for one accounting number in table1.
    So I did if else condition in accounting number in resultset as following:
    List<AccRecord> retval = new ArrayList<AccRecord>();
    while(rs.next())
    //instance of account record
    AcciRecord acct1 = new AccRecord();;
                   if(acc_No != accountNumber)
                           //then get all data from table1                    
                   acc1.setEmpId(rs.getInt("ACC_ID"));
                             acc1.setEmpId(rs.getString("Acc_Name"));//and other 20 fields like this
              else if(acc_No == accountNumber) //this is where it breaks down if same acc number has more than one row in table2,we don't //want to get all other data again from table1
                                                 //also get all data associated with that accounting number from table2
                                 Other other1 = new Other();                         
                                 other1.setEmpId(rs.getInt("EMP_ID"));//these are datas from table2
                                 other1.setjobCode(rs.getString("JOB_CD"));
                                 other1.add(crew1);
    retval.add(acc1);
    }My question is how can I make logic right, in above code for the first account number it will go to else if condition (coz very first time acc number is never going to be different then previous accounting number,so it won't get my accounting data, the way I have compared it)
    I want to code like for one accounting number it brings all accounting data and for that accounting number it also brings all employee data (which is in table2) which will more than one entires,
    So..when accounting number is same as previous it shouldn't get all data again from table 1 ,it should go to only else if condition to get data from table 2 , it should go to my if block only when there is a new accounting number, in other words when there is next record in table1
    Can anybody help me??
    Please...
    Thanks
    Edited by: ASH_2007 on Mar 28, 2008 11:55 AM

    hi there,
    thanks for ur feedback
    but it is always going to contian accno .. so it will never go in your condition
    May be I haven't explained it well
    I need something which gets all data for every new account number in table 1
    Now for that same account number, table2 have 3 rows including that account number 3 times (I am connecting this 2 tables with acc no, table 1 doesn't have duplicate acc no but table 2 does)So my resultset runs 3 times for the first record in table 1, because for that accno table 2 has 3 entries
    This is because my sql is as follow,,which I have to,,I can't change due to requirements...
    SELECT A.accNumber, A.Date, B.EMP_ID, B.JOB_CD
    FROM Table A,  Table B,  (SELECT SSA.accNumber FROM Table SSA, Table SSB       
        WHERE SSB.EMP_ID = ?  AND
       SSA.accNumber = accNumber) C          
    WHERE A.accNumber = C.accNumber                                            
       AND A.accNumber = B.accNumber                        
    //so if I do: like this in my resultset
    while(rs.next())
    Integer accNumber = rs.getINt(accNumber);
    accno =accnumber;
    if (accno != accNumber)
    { get all account data
    else if(accno == accNumber)
    { get all other data
    }but question is it will not satisfy my if condition , because for a new record ,in this case,in first record acc number will never match...
    I appreciate your help and time
    Please help me
    THnaks
    Edited by: ASH_2007 on Mar 28, 2008 1:54 PM

  • Need help with a For loop that uses a Break statement

    I need to create a for loop which counts down from 100-50 and divides the number being counted down by a counter. Can anyone help me?
    public class Break
    public static void main ( String args []) (;
         int total = 0
         int counter = 0
         for { (int number = 100; total >=50; total --)
         if (counter == 0)
         break;
         } // end of for loop
         int output = number/counter
         system.out.printf("The number is" %d output/n)
         }// end of method main
    }// end of class Break

    Im sorry I didnt explain myself very well i do not need the break statement at all.
    I now have this code:
    public class BreakTest
       public static void main( String args[] )
          int count; // control variable also used after loop terminates
         for (int i = 100; i >= 50; i = ++count)
       if (i >= 50) {
        continue;
          System.out.printf( "\nBroke out of loop at count = %d\n", count );
       } // end main
    } // end class BreakTest
    /code]
    and i get these error messages:
    F:\csc148>javac BreakTest.java
    BreakTest.java:9: variable count might not have been initialized
         for (int i = 100; i >= 50; i = ++count)
                                          ^
    BreakTest.java:15: variable count might not have been initialized
          System.out.printf( "\nBroke out of loop at count = %d\n", count );
                                                                    ^
    2 errors                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Need help with a for loop

    Hi all
    I have a dir that has a list of folders that are created using php that my customers upload to. the PHP creates a new folder using the system date on the days that they upload. (using this format yyyymmdd)
    What I am trying to do is loop thou the folders and get todays folder and list the files that are in todays folder. I have been able to do this up to the point of if a customer folder does not have a folder called todays date.
    I know I need some sort of try / catch but don't know what.
    Can anyone help me please
    Thanks for you time and help in advance
    Craig
      public void getfolderList() {
        File dir = new File("/Users/craig/Documents/jBuilder_Epod/copy");
        File[] getFolderNames = dir.listFiles();
        if (getFolderNames != null) {
          for (int gf = 0; gf < getFolderNames.length; gf++) {
            String store = "" + getFolderNames[gf];
            if (!store.endsWith(".DS_Store")) { // This is a mac file name Only
              String folderName = "" + getFolderNames[gf];
              if (!store.endsWith(".DS_Store")) { // This is a mac file name Only
                //I need to have some sort of try and Catch here.
                // If there is no Folder called "todaysFileName" I need to go to the next folder
                //i.e. stop the for loop and go to next
                String setTodaysFileName = folderName + "/";
                String todaysFileName = setTodaysFileName + systemDate;
                File todaysFolder = new File(todaysFileName);
                File[] todaysFiles = todaysFolder.listFiles();
                for (int td = 0; td < todaysFiles.length; td++) {
                  todaysFileName = "" + todaysFiles[td];
                  System.out.println("There is no folder Today........" +
                                     todaysFileName);
      }

    A quick guess would be that after the sStatement
      File[] todaysFiles = todaysFolder.listFiles();todaysFiles is null if todaysFolder doesn't exist and you get a NullPointerException when trying to access todaysFiles.length in the following for-loop.
    If that doesn't help, please be a bit more precise what kind of Exception occurs...

  • Help with stopping a loop..and more :)

    I have a web site called MyNextPet.org. I want to have a
    featured pet on the
    home page that is Random
    I am attempting to write a function that does this:
    Selects the total pets in the database ('Pets') and generate
    a RecordCount
    Create a variable that is random from 1 to the RecordCount of
    'Pets'
    Attempt to select information about that pet based on the
    generated number
    (that must match the auto incremented 'pettag' number)
    If the number does not match any of the pets, loop through an
    do it again
    If the number does match, stop and output the information
    selected
    I winged this function so I am sure I did something wrong and
    the fact that
    I am posting it proves that I did. I am a little (or a lot)
    confused on how
    to break out of a loop if the condition is met.
    Help!
    Code I have:
    <cffunction name="GetFeaturedPet" access="public"
    returntype="query">
    <cfquery name="Pets" datasource="#Request.MainDSN#">
    SELECT * FROM pets
    </cfquery>
    <cfloop>
    <cfset featured = RandRange(1,#Pets.RecordCount#)>
    <cfquery name="GetFeatured"
    datasource="#Request.MainDSN#">
    SELECT P.name, p.age, p.gender, p.breed, R.org
    FROM pets P LEFT OUTER JOIN rescues R
    ON p.username = R.username
    WHERE pettag = #featured# AND active = 1
    </cfquery>
    <cfif #GetFeatured.RecordCount# EQ 0>
    </cfloop>
    </cfif>
    <cfelse>
    <cfabort>
    <cfreturn GetFeatured>
    </cffunction>
    Wally Kolcz
    Developer / Support

    Try this modified function. The first query will pull all
    active pets from your db. The second QoQ ("getPet") will pull one
    random pet from the first query.
    <cffunction name="GetFeaturedPet" access="public"
    returntype="query">
    <cfquery name="GetFeatured"
    datasource="#Request.MainDSN#">
    SELECT p.pettag, P.name, p.age, p.gender, p.breed, R.org
    FROM pets P LEFT OUTER JOIN rescues R
    ON p.username = R.username
    WHERE active = 1;
    </cfquery>
    <cfset featured =
    RandRange(1,#GetFeatured.RecordCount#)>
    <cfquery name="getPet" dbtype="query">
    SELECT * FROM GetFeatured WHERE pettag = #featured#
    </cfquery>
    <cfreturn getPet>
    </cffunction>

  • Help with scrolling Panel loop

    Hi,
    I doing a flash scrolling Panel creating the buttons dynamic
    with xml, like the scroll panel made in gotoandlearn "scrolling
    thumbnail Panel" but creating each button with xml. well this works
    fine.
    but I want to do if a panel that loop if I move the mouse
    right or left any idea to do this?
    I hope some see the code that I have now..
    saludos
    Carolina

    Check out this link: The Tom Kyte Blog: Varying in lists...

Maybe you are looking for

  • Sharing music and videos but not mobile apps btw 2 accts on same Mac

    My wife and I each have accounts on our Mac. When we sync our iPhones, I want each of us to be able to sync our own music and video playlists (from a common repository) but *keep our iPhone apps separate*. We are kind of doing it now, but I'm not qui

  • In DB-13 Initialize tape error

    Hi while initialize tape in db-13, it gave error like ob started tep 001 started (program RSDBAJOB, variant &0000000000119, user ID BASIS) xecute logical command BRBACKUP On host CRMDEV arameters: -u / -i force -c force -n 1 -v SCRATCH R051I BRBACKUP

  • Elicense control error

    Hello all.  Everytime i try to start logic without my nexus license dongle i get the eLicense control error and logic refuses to start.  The problem is that I do a lot of work in logic on the plane and in hotel rooms and don't always have my license

  • How can I make the recently viewed web sites change color on my browser?

    How do I get firefox to change the color of recently viewed web sites? Mac OS 10.6.8 Latest Firefox Update I have tried <Firefox <Preferences <Content <Colors

  • What is included in the calculation functionality of the database?

    Hi there, I have read that - as SAP BW has to support several database products - the set of calculation functionality has been reduced to the lowest common denominator. Is that correct? What are the calculation commands that are processed by the dat