VideoHelp Forum

Our website is made possible by displaying online advertisements to our visitors. Consider supporting us by disable your adblocker or Try ConvertXtoDVD and convert all your movies to DVD. Free trial ! :)
+ Reply to Thread
Results 1 to 18 of 18
Thread
  1. i just can not figure out - too tired.
    Code:
    i = 0;
    x = 0;
    y = 0;
    bool sL = 0;
    while( sL ) 
            {
    	while( y  >=  0 ) {
    		if( x < bkSz  &&  y < bkSz ); 
            {		
    			dS[*i*][*0*] = x;
    			dS[*i*][*1*] = y;
    			i++
    	}
    		y−−;
    		x++;
    	}
    	y = x;
    	x = 0;
    	if( i  >=  bkSz * bkSz )
    		sL = 1;
    }
    what is wrong here?
    Last edited by enim; 19th Feb 2014 at 17:02.
    Quote Quote  
  2. the outer while loop will never be entered since 0 <> false.
    also next time use 'code'-tags if you post code
    Quote Quote  
  3. Selur,

    Do you ever run a bit slower?
    I was, definitely, expecting you, but, not too fast!
    Last edited by enim; 19th Feb 2014 at 17:05.
    Quote Quote  
  4. Guest34343
    Guest
    Wouldn't it have been obvious single-stepping through the code?
    Quote Quote  
  5. Member
    Join Date
    Sep 2012
    Location
    Australia
    Search Comp PM
    Um, wouldn't it have been obvious just knowing it doesn't work, and glancing at it? Or is that just me?

    Originally Posted by Selur
    0 <> false
    Do you mean 0 == false? Or are you not referring to the Basic operator?
    Quote Quote  
  6. Banned
    Join Date
    Nov 2005
    Location
    United States
    Search Comp PM
    Originally Posted by ndjamena View Post
    Um, wouldn't it have been obvious just knowing it doesn't work, and glancing at it? Or is that just me?

    Originally Posted by Selur
    0 <> false
    Do you mean 0 == false? Or are you not referring to the Basic operator?
    i actually think that since the OP is setting sL to false and the while loop is effectively being interpreted as while (false) which is always true, then the program does make it past the outer while condition.

    the second loop says while y is greater than or equal to 0 evaluate the rest but then he decrements y outside of the inner while loop, so the next time y gets tested it's less than 0 and thus the inner loop is only being executed once and then the gets evaluated as false every other time.
    Quote Quote  
  7. Maybe the OP thought the while() test was made after executing the loop. Which is not the case as it's written. If he want the loop to execute before the test he should use a do... while loop:

    Code:
    do
    {
        blah...
    
    } while( sL );
    Quote Quote  
  8. Member
    Join Date
    Sep 2012
    Location
    Australia
    Search Comp PM
    Code:
    While (0 <> false)
    It took me a few minutes to interpret it properly. Is that c or basic? It looks like c to me but I don't use basic.
    Quote Quote  
  9. Member
    Join Date
    Sep 2012
    Location
    Australia
    Search Comp PM
    Originally Posted by jagabo View Post
    Maybe the OP thought the while() test was made after executing the loop. Which is not the case as it's written. If he want the loop to execute before the test he should use a do... while loop:

    Code:
    do
    {
        blah...
    
    } while( sL );
    Right, he got it all backwards

    Code:
    i = 0;
    x = 0;
    y = 0;
    bool sL = 1;
    while( sL ) 
            {
    	while( y  >=  0 ) {
    		if( x < bkSz  &&  y < bkSz ); 
            {		
    			dS[*i*][*0*] = x;
    			dS[*i*][*1*] = y;
    			i++
    	}
    		y−−;
    		x++;
    	}
    	y = x;
    	x = 0;
    	if( i  >=  bkSz * bkSz )
    		sL = 0;
    }
    -Edit- That was fun.
    Quote Quote  
  10. Guest34343
    Guest
    Originally Posted by ndjamena View Post
    Um, wouldn't it have been obvious just knowing it doesn't work, and glancing at it? Or is that just me?
    Well sure, but the OP didn't get it. When something doesn't work as expected, and you can't see why from inspection, you turn to debugging.
    Quote Quote  
  11. Member
    Join Date
    Sep 2012
    Location
    Australia
    Search Comp PM
    Originally Posted by enim View Post
    - too tired.
    I guess you've just got to identify what the problem actually is, and fix it.
    Quote Quote  
  12. Do you mean 0 == false? Or are you not referring to the Basic operator?
    What I wanted to indicate with me posting '0 <> false' was that '0' is equivalent to 'false' and since 'sL' was set to '0' before the while-loop and then taken as the condition for the while loop, the loop is never entered.

    Sometimes it needs someone else to look at the code, even if you know the line where the bug is, you sometimes simply don't the problem since you already looked at code for too long.
    Quote Quote  
  13. Banned
    Join Date
    Nov 2005
    Location
    United States
    Search Comp PM
    Originally Posted by Selur View Post
    What I wanted to indicate with me posting '0 <> false' was that '0' is equivalent to 'false' and since 'sL' was set to '0' before the while-loop and then taken as the condition for the while loop, the loop is never entered.
    actually the loop is entered, sL is set to 0 and then tested in the while conditional, but the while statement becomes while (false) which is always the case since he set it to false just prior to the loop, so the program proceeds past the outer loop and into the inner loop.

    think about it for a while, if the test was while (0), the end result is that it's always zero and thus it always gets executed.
    Quote Quote  
  14. Originally Posted by deadrats View Post
    Originally Posted by Selur View Post
    What I wanted to indicate with me posting '0 <> false' was that '0' is equivalent to 'false' and since 'sL' was set to '0' before the while-loop and then taken as the condition for the while loop, the loop is never entered.
    actually the loop is entered, sL is set to 0 and then tested in the while conditional, but the while statement becomes while (false) which is always the case since he set it to false just prior to the loop, so the program proceeds past the outer loop and into the inner loop.
    In the OP's original post nothing inside the outer while loop is ever executed. Zero is the definition of false. So the test condition is always evaluated as false. The OP's original code is equivalent to:

    Code:
    i = 0;
    x = 0;
    y = 0;
    bool sL = 0;
    In fact, a good optimizing compiler would reduce it down to that (maybe less, depending on what follows).

    Originally Posted by deadrats View Post
    think about it for a while, if the test was while (0), the end result is that it's always zero and thus it always gets executed.
    No, it's not executed. Try it. The opposite, while(1), creates an endless loop (in the absence of a break inside the loop).
    Last edited by jagabo; 3rd Jun 2014 at 08:56.
    Quote Quote  
  15. actually the loop is entered, sL is set to 0 and then tested in the while conditional, but the while statement becomes while (false) which is always the case since he set it to false just prior to the loop.
    a while-loop (while(condition) {TODO}) is only executed if the condition evaluates to true, whether the condition changed or not is of no concern and since 0 is equivalent to false (and thus evaluates to false) the loop is never executed.
    Quote Quote  
  16. Thanks everybody for inputs. In fact, Selur's very quick and very first response was very helpful.
    I was too tired b'coz grabbing a beer was out of reach that time.
    Lately got too busy on absolutely different things.
    Quote Quote  
  17. Member
    Join Date
    Sep 2012
    Location
    Australia
    Search Comp PM
    Um...

    Code:
    while(i  <  bkSz * bkSz )
    You could save yourself a variable.

    or if you need to enter at least once start with 'do'

    -Edit-

    Code:
    if ( i  >=  bkSz * bkSz )
               break;
    Quote Quote  
  18. Member
    Join Date
    Sep 2012
    Location
    Australia
    Search Comp PM
    Originally Posted by enim
    simple while loop, what is wrong here?
    The semi-colon after the if statement should be after the i++ instead...
    Quote Quote  



Similar Threads