Why doesn't the following method recurse infinitely?

The following method opensquare should cause infinite recursion as far as I can see and yet it doesn't cause lockups or error messages of any kind when I run it in my program. Also I can't figure out why showgrid[x+b][x+c] isn't set to true for certain values of b and c between -1 and 1 even on the initial call (opensquare called for 1st time).
Info about variables, arrays: x,y are always between zero and 9 and are passed to opensquare from a mousepressed method which converts the
pixel coordinates to minegrid, showgrid etc. coordinates between 0..9.
and showgrid[x][y] is always true before opensquare is called. For
recursive calls it looks to me like showgrid[x][y] will always be true.
showgrid, minegrid are 10 by 10 arrays of type boolean
number grid is a 10 by 10 array of type int
b & c are local ints to the method opensquare, specifically the for loops.
assuming that the if test condition is passed and none of the squares around x,y has numbergrid>0 I would think that the method would call itself infinitely because for b& c=0 from the two for loops would mean the method would call itself for the same element (x+0,y+0)=x,y the same element. Also it would jump to one element and then the method would execute for the element it just jumped from and go back and forth... and yet this method doesn't infinitely recurse. Also, it doesn't seem to call opensquare for some values of b&c even though it passes the test condition.
I really don't understand this. Could someone explain 1) why it doesn't infinitely recurse and 2) why for a (showgridl[x][y] element that doesn't for -1>b>1 -1>c>1, have any numbergrid[x+b][y+c] elements>0 around it and for -1>b>1 -1>c>1 no minegrid[x+b][y+c] elements that are true around it and meets the condition that [x+b]&[y+c] are both between 0 and 9) that it doesn't make showgrid[x+b][x+c] true for every x+b & y+c. In my program it doesn't make it true for every x+b,y+c assuming the previous conditions. It seems to head off in a direction of openingsquares in a x getting smaller y getting smaller direction and never seems to make showgrid[x+b[y+c] true for b>0&c=0.
here is the method:
public void opensquare(int x,int y){   
int count=0;
int squarecount=0;
if (minegrid[x][y])
{ done=true;}
while (!done) {
if (showgrid[x][y]) {
for (int b=-1; b<=1; b++)
for (int c=-1; c<=1; c++)
if ((x+b >= 0) && (x+b < XGRID) && (y+c >=0) && (y+c<YGRID) && (minegrid[x+b][y+c] == false ))
showgrid[x+b][y+c]=true;
if (numbergrid[x+b][y+c] > 0) {
done = true;
x=x+b; y=y+c;
opensquare(x, y);
else done=true;

done is a boolean global variable and is transparent to all methods. The mousepressed method sets done to false every time the left mouse button is pressed. Opensquare is called from the mousepressed method after done is set to false.
You say it's not recursion, it sure acts like recursion.
I get elements in showgrid being opened that are as far as 4 elements less in x and y then the element passed to opensquare. I get a max of about 14 elements of showgrid being set to true when they were all false before opensquare was called. Since the for loops only run through 9 elements of showgrid it must be calling opensquare again which then opens more elements, unfortunately it usually only runs in one direction with x and y getting smaller and to a lesser extent x getting bigger and y getting smaller. It almost never sets showgrid[x][y] elements to true with x and y getting bigger. It is recursion ( the method calling itself is what I understand as recursion). I don't understand why it doesn't recurse infinitely as I explained before with adjacent showgrid elements calling opensquare for each other infinitely, or even a showgrid element producing a call to opensquare for itself infinitely. If I take out the else done=true statement I get multiple errors displayed in the applet viewer window coming from opensquare (I can't see the error it goes by too fast). Seems to me if it fails the boundary test done will never be true for every single branch of opensquare called.

Similar Messages

  • How to remove the recursion from the following method

    Hi All,
    Can u plz help me to remove the recursion from the following method.
    The problem here is that recursion cann't be removed easily here as there is no any end condition.
    hopefully waiting for the help....
    Reema.
    private FilterStatement processCustomExpressions(FilterStatement statement,
              DistinguishedName tenant, LdapDao ldapDao)
              throws NameNotFoundException,
              LDAPServerException, NamingException {
         HashMap relMap = new HashMap();
         HashMap replaceMap = new HashMap();
         Vector relVec = null;
              FilterSubExpressions expressions = statement.getExpressions();
              FilterPartIterator it = (FilterPartIterator)expressions.iterator();
              while (it.hasNext()) {
                   FilterExpression e = (FilterExpression)it.next();
                   if (e instanceof CustomExpression) {
                        CustomExpression ce = (CustomExpression)e;
                        try {
                             FilterExpression fe = ce.createExpression();
                             if (fe instanceof RelationshipExpression) {
                                  RelationshipExpression re = (RelationshipExpression)fe;
                                  it.replace(re);
                                  relVec = (Vector) relMap.get(re.name);
                                  if(relVec == null) {
                                       relVec = new Vector();
                                       relVec.add(re);
                                  }else {
                                       relVec.add(re);
                                       it.remove();
                                  relMap.put(re.name, relVec);
                             } else if (fe instanceof SystemExpression) {
         SystemExpression se = (SystemExpression)fe;
         it.replace(se);
                        } catch (FilterEvaluationException fe) {
                             traceLogger.exception(Level.DEBUG_MIN, this,
                                  "processCustomExpressions(" + statement.toString() + ")", fe);
                             SystemLog.getInstance().logError(this,
                                  "processCustomExpressions(" + statement.toString() + ")", fe.getMessage());
              replaceRelationshipExpressions(statement, tenant, ldapDao, relMap);
              processContainerBasedExpressions(tenant, ldapDao, relMap, replaceMap);
              FilterSubStatements statements = statement.getStatements();
              FilterStatement temp = null;
              if (statements.size() != 0) {          
                   FilterPartIterator iter = (FilterPartIterator)statements.iterator();
                   while (iter.hasNext()) {
                        temp = (FilterStatement)iter.next();
                        temp = processCustomExpressions(temp, tenant, ldapDao);
                        iter.replace(temp);
              if(!replaceMap.isEmpty())
                   return replaceContainerBasedExpressions(statement, replaceMap);
              return statement;
         }

    I think one of the reasons that noone will reply to your posting is that you take it a bit too easy. First of all, please use the "code" button to format your code listings. Then it will look like this (see below) and everybody can at least read it!
    private FilterStatement processCustomExpressions(FilterStatement statement,
                                                    DistinguishedName tenant,
                                                    LdapDao ldapDao)
            throws NameNotFoundException, LDAPServerException, NamingException {
        HashMap relMap = new HashMap();
        HashMap replaceMap = new HashMap();
        Vector relVec = null;
        FilterSubExpressions expressions = statement.getExpressions();
        FilterPartIterator it = (FilterPartIterator) expressions.iterator();
        while (it.hasNext()) {
            FilterExpression e = (FilterExpression) it.next();
            if (e instanceof CustomExpression) {
                CustomExpression ce = (CustomExpression) e;
                try {
                    FilterExpression fe = ce.createExpression();
                    if (fe instanceof RelationshipExpression) {
                        RelationshipExpression re = (RelationshipExpression) fe;
                        it.replace(re);
                        relVec = (Vector) relMap.get(re.name);
                        if (relVec == null) {
                            relVec = new Vector();
                            relVec.add(re);
                        else {
                            relVec.add(re);
                            it.remove();
                        relMap.put(re.name, relVec);
                    else if (fe instanceof SystemExpression) {
                        SystemExpression se = (SystemExpression) fe;
                        it.replace(se);
                catch (FilterEvaluationException fe) {
                    traceLogger.exception(Level.DEBUG_MIN, this,
                                "processCustomExpressions("
                                + statement.toString()
                                + ")",
                            fe);
                    SystemLog.getInstance().logError(this,
                                "processCustomExpressions("
                                + statement.toString()
                                + ")",
                            fe.getMessage());
        replaceRelationshipExpressions(statement, tenant, ldapDao, relMap);
        processContainerBasedExpressions(tenant, ldapDao, relMap, replaceMap);
        FilterSubStatements statements = statement.getStatements();
        FilterStatement temp = null;
        if (statements.size() != 0) {
            FilterPartIterator iter = (FilterPartIterator) statements.iterator();
            while (iter.hasNext()) {
                temp = (FilterStatement) iter.next();
                temp = processCustomExpressions(temp, tenant, ldapDao);
                iter.replace(temp);
        if (!replaceMap.isEmpty())
            return replaceContainerBasedExpressions(statement, replaceMap);
        return statement;
    }Second, when you cannot understand your own code anymore, simplify it! As far as I can see, there are two "main" processes (i.e. loops) in your method, where the second one calls the method recursively. Split the method into two. Furthermore, write a third method that processes the iterated elements and call that method from out of the loops.
    I did'nt analyse your method and have no idea what it does at all. I'm merely telling my first impression.
    Good luck.

  • Why Doesn't the XIRR function work?

    In Excel if you have 5 records from a1:b5 then XIRR looks like this:
    XIRR(A1:A5, B1:B5) you get a nice neat answer like .35
    Here is a version that works in Crystal that would require manual entry of any new quarters numbers and dates-- and if you plug this into Crystal it works:
    (XIRR([1000000,-100000,-100000,-100000,-100000,10277.49,-100000], [DateValue(1999,2,1),DateValue(1999,3,1),DateValue(1999,6,1), DateValue(1999,12,1),DateValue(2000,3,1),DateValue(2000,6,1),DateValue(2000,9,1)]))*.100
    You do get a nice answer of something like .035.  But this is all done manually and I need it to function automatically when the report is refreshed.
    So you have a range for the currency and a range for the date fields. I need to simulate this in crystal. Crystal has an XIRR function, and with the arrays, I should be able to fill in the range, but am having difficulty getting it to work.
    After building the arrays, I made another formula to combine the arrays in the XIRR formula.
    I am down to this error now after getting this formula this far  --
    "Numerical method did not converge; try another value for guess."
    Here's where I am with the formula, although they don't want to use the guess part of the XIRR function - they just want to use the XIRR(number/currency, date).  Maybe you could pass this on too?:
    /{@Reset} for the group header (NOT using a repeated group header):
    whileprintingrecords;
    numbervar array x := 0;
    datevar array y := date(0,0,0);
    numbervar i := 0;
    numbervar j := 0;
    //{@accum} for the detail section:
    whileprintingrecords;
    numbervar array x;
    datevar array y;
    numbervar i := i + 1;
    numbervar j := count({table.groupfield},{table.groupfield});
    if i <= j then (
    redim preserve x[j];
    redim preserve y[j];
    x<i> := tonumber({table.currency});
    y<i> := datevalue({table.datetime})
    //{@xirr calc} to be placed in the group footer:
    whileprintingrecords;
    numbervar array x;
    datevar array y;
    xirr(x,y)
    The array works correctly.  So why do I get that error and why doesn't the XIRR formula work like they say it should?  Has anyone used this successfully in Crystal--maybe you could shed some light?
    Thanks!

    Hi,
    I am receiving that same error when the last item in the array is 0, otherwise all works perfectly.
    When I run the same group of numbers and dates in Excel it returns without issue.
    -265500.00,-690000.00,-570000.00,16814.25,-855000.00,-619500.00,55293.46,30411.40,15183.76,  0.00
    01-25-2007,03-06-2007,05-02-2007,06-29-2007,08-01-2007,08-24-2007,09-17-2007,03-14-2008,05-28-2008,03-31-2010
    =XIRR(A2:J2,A1:J1,-0.1)
    Is there a known bug in Crystal's XIRR function when the last value is 0? 
    Or a hot-fix that will repair this?
    Thanks in advance,
    Gary
    PS. I am using Crystal XI Product Version: 11.0.0.2495

  • Why doesn't the new flash player I downloaded work on my mac?

    Hi,
    I download the last new flash player on my mac under Lion and I can't open some website like adobe websites

    Hi Sunil,
    I try http://www.adobe.com/software/flash/about/ and the file attach is the result: a white page.
    I uninstall it yesterday and download the last version on adobe
    it's on firefox, I can use safari but I need to reload many time to have something
    Le 27 sept. 2011 à 13:09, Sunil_Bhaskaran a écrit :
    Re: Why doesn't the new flash player I downloaded work on my mac?
    created by Sunil_Bhaskaran in Flash Player - View the full discussion
    After downloading, you need to run the installer.
    Could you please visit this site: http://www.adobe.com/software/flash/about/
    If Flash Player is installed in your machine, it will give you the version number.
    In the following link, you have step-by-step instructions on installing Flash Player on Mac:
    http://kb2.adobe.com/cps/908/cpsid_90893.html
    Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: http://forums.adobe.com/message/3940045#3940045
    To unsubscribe from this thread, please visit the message page at http://forums.adobe.com/message/3940045#3940045. In the Actions box on the right, click the Stop Email Notifications link.
    Start a new discussion in Flash Player by email or at Adobe Forums
    For more information about maintaining your forum email notifications please go to http://forums.adobe.com/message/2936746#2936746.

  • Why doesn't the App store recognise that I already have Facetime installed and want me to repurchase it?

    Why doesn't the App store recognise that I already have Facetime installed and want me to repurchase it?  I also canot upgrade from V3 to V 1.02?

    For some reason the Apple servers are having an issue retaining the bank card's CVV code (three digit security code) in the payment method area. Every time I run into an issue, whether in the iTunes Store or the Mac App Store, when I check my account info the CVV code has been missing every time!
    Try resolving the problem from iTunes, you have more access to your account details in iTunes. Sometimes it seems that when there is a problem with incorrect or incomplete information regarding your method of payment the Mac App Store's warnings get confusing.
    Open iTunes, enter the iTunes Store, then log in and review your account information. Make sure that the billing address is correct and that if needed, the CVV code, the three digit security code from your bank card, is correct. On your way out reset the notifications.

  • Why doesn't the iPad have a guest screen like the PC for extra security?

    I just want to start off first by saying I just purchased my iPad about six months ago and I'm really enjoying it,but if you're like me,I believe in protecting my privacy.
    I don't like to turn down any of friends or coworkers when I'm asked to use my iPad,but when you have such things as your personal pictures,movies,music,business documents,etc...you'd like to keep them from prying eyes. I thought that with the new iOS 7 update,that issue would've been fixed, but I was wrong. I'm hoping Apple would correct this problem with the next iOS update,it would make a lot of loyal Apple consumers &amp; anyone who's new to purchasing the iPad for the first time very happy to know that feature is available.
    Why doesn't the iPad offer a guest screen?

    Tell Apple at the link below.
    http://www.apple.com/feedback/ipad.html

  • Why doesn't the CC app work properly?

    I've been using Creative Cloud for some time now and am really loving it, however I must say it is a source of annoyance that the Creative Cloud app just doesn't work properly.
    Firstly, I used it initially to download all my apps, then after an update those apps no longer appeared in the "Apps" list. Now only those that have been installed since that update appear in this list. Why doesn't the "Apps" list display all of the Adobe CC apps that I have installed on my computer?
    Why does it keep reinstalling fonts? I'm always getting "Lush Script Regular" and other fonts being added.
    It regularly comes up telling me that Dreamweaver and Premiere Pro need to be updated, but always I get an error, then the update request disappears.
    I'm regularly getting 4 files that it can't sync - even though they are the same files as others in the folder. If nothing else, why can't I say "Great, got the message". Also, why is the error message just "due to server error" with no advice on how to resolve it? Why is there a server error on only these 4 files?
    It seems to me there are still some teething issues with the CC app, but what I don't understand is why they aren't being resolved much faster, given that this is the portal to the service.
    Of course, given Adobe I doubt I'll get satisfactory answers – a little jaded with their responses. Anyway, thought I'd at least post the questions.  

    Questapo I am sorry you have been facing difficulties with your Creative Cloud experience.  I don't believe it will be possible to address all of your concerns in one discussion.  I would not be surprised if at least three of the issues are related to the same root cause.
    First in order for the applications to be visible are you regularly needing to delete the OPM.db file?  You can find this listed as solution 2 in CC desktop lists applications as "Up to Date" when not installed - http://helpx.adobe.com/creative-cloud/kb/aam-lists-removed-apps-date.html.

  • Why doesn't the location information in an iCal meeting show up on my iPhone, when it does show up in iCal?

    Why doesn't the location information show up on my iPhone 4S calendar when I accept an invitation to a meeting?
    The other information such as the date, time and invitees all show up on the iPhone, while in iCal all the information including the Location field is showing up.

    If it won't charge you probably need to try a different dock to usb cable.  More information on troubshooting this is available here:  http://support.apple.com/kb/TS1591.

  • Why doesn't the weather icon display the current temperature in your "local" city?

    Why doesn't the current temperature display in the weather icon on the home screen?

    The application works and I do have location-based services on. I'm just wondering why the icon itself does not show the current temperature. Sort of how they upgraded the clock after show the current time.

  • Why doesn't the "back" button work all the time in Safari?

    Why doesn't the "back" button work all the time in Safari?

    thanks for the reply. You prompted me to check and I realised it wasn't installed on my test laptop and opening in Microsoft Reader. I've installed it now and it works.
    My next challenge is to prevent the mailto: command opening Microsoft Mail instead of Outlook, but I guess every user will have a different default.
    Thank you

  • Why doesn't the repair box in Aperture show up? and if it does, once you choose repair does it give you an indication it is working?

    Why doesn't the repair box in Aperture show up? and if it does, once you choose repair does it give you an indication it is working?

    Winterwren22 wrote:
    Why doesn't the repair box in Aperture show up?
    Without more information, speculation is a waste of time.  At the least tell us what you do, what the results are, and how that result differs from your expectation.  Then tell us what steps you have taken to resolve the issue, and what the results of taking those steps was.
    once you choose repair does it give you an indication it is working?
    Adjustments you make are shown live.
    Instructions on the use of Repair Brush are here (ignore "Spot & Patch" -- it is superannuated).

  • I have Adobe Reader X on Windows Vista. Why doesn't the Printer for Adobe PDF show up in my Hardware/printers? Or can I add it to the Hardware/Printers?

    I have Adobe Reader X in Windows Vista. Why doesn't the Adobe PDF show up as a printer in my Hardware/Printers? Or can I add it to the Hardware/Printers? And how?

    Adobe Reader - FREE - reads PDF files, prints them, fills forms.
    Adobe Acrobat - $$ - as Reader, and makes PDFs and edits them, sorta, and does a bunch more.
    So if you had Acrobat try and find the license to avoid having to pay again...

  • Why doesn't the sd card or the usb connect to my mac ????

    why doesn't the sd card or the usb connect to my mac plzzzz help meeeeeeeeeee

    The reason no one has replied is that you posted in a little-viewed forum for an obsolete Apple software suite. I am asking the Hosts to move you to the MacBook Air forum.
    Also these forums are NOT chat rooms so you will seldom get an instant answer. No one here works for Apple; we are end users like you who volunteer on a time-available basis to help our fellow Mac users. Patience is required here.

  • Why doesn't the rotate gesture on my trackpad behave as it used to for switching between tabs when it works the same with all other programs besides Firefox?

    Why doesn't the rotate gesture on my trackpad behave as it used to for switching between tabs when it works the same with all other programs besides Firefox?
    I changed the about:config to make the rotate gesture move between tabs, and it worked great for well over a year. Now it behaves erratically as described here:
    https://bugzilla.mozilla.org/show_bug.cgi?id=877598
    It used to be very controllable to move one tab over, now it is erratic and moves quickly and to unexpected tabs regardless of how slow I do the rotate gesture. This is the main reason I use Firefox over Chrome and I would like to continue to do so unless there is no fix to this.

    Just set the browser.gesture.twist.threshold to something around 15-25.

  • HT1368 Why doesn't the Add to Wish List icon appear on my iPhone 5? I have iOS 7...frustrating

    Why doesn't the Add to Wish List icon appear on my iPhone 5? I have iOS 7...frustrating

    If it's not a free item then you should get the 'add to wish list' icon via the share button - is it a free or paid-for item that you are looking at ?

Maybe you are looking for

  • Crystal report printing in halfsize paper

    Hi Guys,      Can you help me printing my crystal report 2008 report in half sheet? i want to print it in size 8x6. i did create a printing profile in printer and set it in default. but when i click the print button and check the preferences it alway

  • My buttons look just awful - what am I doing wrong?

    I'm trying to make some simple text buttons that are gray when not selected, and white when selected. I've attached a picture of what this looks like when I try to do this with a DVD Studio Pro button in a "normal" (non-layered) menu (note: I did not

  • PI 7.1 including Enhancement Pack1

    Hello, I'm trying to find information, to see if it's possible to upgrade the existing PI 7.0 (on Windows 32bit) to PI 7.1 inc EhP1. All I see is 64bit info everywhere? is it really, I can't move forward with this upgrade or I'm not looking correctly

  • New number range to MOTIVID

    Hi Gurus When a new Ad spac (motiv) is entered and post to the database, a Tech-ID (JHAMOT- MOTIVID) is generated by the system, stored in the respective JHAMOT and displayed to the user. I want to attach new number range to MOTIVID, is it possible t

  • How to make object dissapear and reappear?

    I was watching a video on YouTube on how to make an explosion. However, the video is not very helpful as the guy doesn't explain anything. I am not a complete newbie, but I still need some help on simple stuf sometimes. The part I am stuck on is when