Re: [PHP] Nested loopa
On Dec 26, 2012, at 10:09 AM, Jim Giner jim.gi...@albanyhandball.com wrote: While I fully understand the purpose of the do...while construct, I just never get used to seeing it used. (in other langs I had to deal with a 'repeat...until construct and dis-liked that also). I pretty much know if I'm going to have to deal with a run at least once when I'm coding and therefore code appropriately, altho I don't know in what ways I've handled it at this very moment. -snip- To me - so much easier to comprehend at first glance. As soon as my eye comes to a block of code starting with a conditional like 'while', I readily see what makes it tick. Again I see the potential usefulness of doing it the other way as you did in your example, but in your case there wasn't a need for using 'do...while' since you structured it so that there was never a case where you had to force the loop to happen regardless of conditions. I too used while's instead of do's for the same reason. However, in my class I had a student show be the light (one can always learn from beginners). Think of it this way, you travel into the code knowing that at some point you're going to repeat the block of code IF a condition is going to be met within the block of code. With that consideration, the 'do/while()' works. Using just a 'while()' for everything means you must determine the what the truth of the 'while()' is going to be AND set that value before the loop. Whereas, using a 'do/while()', you don't need to set the truth until the block of code has been implemented AND at that point determine the truth of the block of code. Cheers, tedd _ t...@sperling.com http://sperling.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Nested loopa
On 12/27/2012 10:42 AM, Tedd Sperling wrote: On Dec 26, 2012, at 10:09 AM, Jim Giner jim.gi...@albanyhandball.com wrote: While I fully understand the purpose of the do...while construct, I just never get used to seeing it used. (in other langs I had to deal with a 'repeat...until construct and dis-liked that also). I pretty much know if I'm going to have to deal with a run at least once when I'm coding and therefore code appropriately, altho I don't know in what ways I've handled it at this very moment. -snip- To me - so much easier to comprehend at first glance. As soon as my eye comes to a block of code starting with a conditional like 'while', I readily see what makes it tick. Again I see the potential usefulness of doing it the other way as you did in your example, but in your case there wasn't a need for using 'do...while' since you structured it so that there was never a case where you had to force the loop to happen regardless of conditions. I too used while's instead of do's for the same reason. However, in my class I had a student show be the light (one can always learn from beginners). Think of it this way, you travel into the code knowing that at some point you're going to repeat the block of code IF a condition is going to be met within the block of code. With that consideration, the 'do/while()' works. Using just a 'while()' for everything means you must determine the what the truth of the 'while()' is going to be AND set that value before the loop. Whereas, using a 'do/while()', you don't need to set the truth until the block of code has been implemented AND at that point determine the truth of the block of code. Cheers, tedd _ t...@sperling.com http://sperling.com There's going to be fans of each method, but my feeling is that I know what I'm doing when I write the code, so setting a condition before the code doesn't faze me. In a way, using the do... format one still sets a condition value before it is evaluated, no? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Nested loopa
A while loop is a blocking call. Be careful with them. --Curtis Tedd Sperling t...@sperling.com wrote: On Dec 26, 2012, at 10:09 AM, Jim Giner jim.gi...@albanyhandball.com wrote: While I fully understand the purpose of the do...while construct, I just never get used to seeing it used. (in other langs I had to deal with a 'repeat...until construct and dis-liked that also). I pretty much know if I'm going to have to deal with a run at least once when I'm coding and therefore code appropriately, altho I don't know in what ways I've handled it at this very moment. -snip- To me - so much easier to comprehend at first glance. As soon as my eye comes to a block of code starting with a conditional like 'while', I readily see what makes it tick. Again I see the potential usefulness of doing it the other way as you did in your example, but in your case there wasn't a need for using 'do...while' since you structured it so that there was never a case where you had to force the loop to happen regardless of conditions. I too used while's instead of do's for the same reason. However, in my class I had a student show be the light (one can always learn from beginners). Think of it this way, you travel into the code knowing that at some point you're going to repeat the block of code IF a condition is going to be met within the block of code. With that consideration, the 'do/while()' works. Using just a 'while()' for everything means you must determine the what the truth of the 'while()' is going to be AND set that value before the loop. Whereas, using a 'do/while()', you don't need to set the truth until the block of code has been implemented AND at that point determine the truth of the block of code. Cheers, tedd _ t...@sperling.com http://sperling.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Sent from my Android phone with K-9 Mail. Please excuse my brevity.
Re: [PHP] Nested loopa
On 12/27/2012 10:47 AM, Curtis Maurand wrote: A while loop is a blocking call. Be careful with them. --Curtis Huh? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Nested loopa
On Thu, Dec 27, 2012 at 4:42 PM, Tedd Sperling t...@sperling.com wrote: On Dec 26, 2012, at 10:09 AM, Jim Giner jim.gi...@albanyhandball.com wrote: While I fully understand the purpose of the do...while construct, I just never get used to seeing it used. (in other langs I had to deal with a 'repeat...until construct and dis-liked that also). I pretty much know if I'm going to have to deal with a run at least once when I'm coding and therefore code appropriately, altho I don't know in what ways I've handled it at this very moment. -snip- To me - so much easier to comprehend at first glance. As soon as my eye comes to a block of code starting with a conditional like 'while', I readily see what makes it tick. Again I see the potential usefulness of doing it the other way as you did in your example, but in your case there wasn't a need for using 'do...while' since you structured it so that there was never a case where you had to force the loop to happen regardless of conditions. I too used while's instead of do's for the same reason. However, in my class I had a student show be the light (one can always learn from beginners). Think of it this way, you travel into the code knowing that at some point you're going to repeat the block of code IF a condition is going to be met within the block of code. With that consideration, the 'do/while()' works. Using just a 'while()' for everything means you must determine the what the truth of the 'while()' is going to be AND set that value before the loop. Whereas, using a 'do/while()', you don't need to set the truth until the block of code has been implemented AND at that point determine the truth of the block of code. Cheers, tedd There are just cases where do/while makes more sense, for example: do { $c = fgetc($fp); } while ($c != 0); if you want to put while in front, you need to duplicate the fgetc call, like this: $c = fgetc($fp); while($c != 0) { $c = fgetc($fp); } Which is worse than the do/while construct. - Matijn
Re: [PHP] Nested loopa
On 12/27/2012 1:29 PM, Matijn Woudt wrote: On Thu, Dec 27, 2012 at 4:42 PM, Tedd Sperling t...@sperling.com wrote: On Dec 26, 2012, at 10:09 AM, Jim Giner jim.gi...@albanyhandball.com wrote: While I fully understand the purpose of the do...while construct, I just never get used to seeing it used. (in other langs I had to deal with a 'repeat...until construct and dis-liked that also). I pretty much know if I'm going to have to deal with a run at least once when I'm coding and therefore code appropriately, altho I don't know in what ways I've handled it at this very moment. -snip- To me - so much easier to comprehend at first glance. As soon as my eye comes to a block of code starting with a conditional like 'while', I readily see what makes it tick. Again I see the potential usefulness of doing it the other way as you did in your example, but in your case there wasn't a need for using 'do...while' since you structured it so that there was never a case where you had to force the loop to happen regardless of conditions. I too used while's instead of do's for the same reason. However, in my class I had a student show be the light (one can always learn from beginners). Think of it this way, you travel into the code knowing that at some point you're going to repeat the block of code IF a condition is going to be met within the block of code. With that consideration, the 'do/while()' works. Using just a 'while()' for everything means you must determine the what the truth of the 'while()' is going to be AND set that value before the loop. Whereas, using a 'do/while()', you don't need to set the truth until the block of code has been implemented AND at that point determine the truth of the block of code. Cheers, tedd There are just cases where do/while makes more sense, for example: do { $c = fgetc($fp); } while ($c != 0); if you want to put while in front, you need to duplicate the fgetc call, like this: $c = fgetc($fp); while($c != 0) { $c = fgetc($fp); } Which is worse than the do/while construct. - Matijn I never said it wasn't useful, just not something I have ever HAD to do. I don't often speak in 4 syllable words either, but once in a while I find the need :) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Nested loopa
On 26/12/2012, at 1:21 PM, Ken Arck ah...@ah6le.net wrote: So I cannot do nested do loops in php? ?php $a = 0 ; $b = 0 ; do { echo $a\n ; do { echo $b\n ; $b++ }while($b =10) ; $a++; }while($a = 20) ; ? You can, though you're never resetting the value of $b in the outer loop, so the inner loop will only run once each time after the first run of the outer. --- Simon Welsh Admin of http://simon.geek.nz/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Nested loopa
On 12/25/2012 4:21 PM, Ken Arck wrote: So I cannot do nested do loops in php? ?php $a = 0 ; $b = 0 ; do { echo $a\n ; do { echo $b\n ; $b++ }while($b =10) ; $a++; }while($a = 20) ; ? You have a typo. Line 8 What are you expecting as output? -- Jim Lucas -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php