Timeline for What is priming the pump? Sometimes called a priming read
Current License: CC BY-SA 4.0
16 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Sep 9, 2022 at 18:39 | comment | added | candied_orange | While it’s not a defect, setting the initial condition outside the scope of the loop when it’s not used outside does cause a scope leak. Which is likely why they gave us the convoluted for(;;) loop. | |
Sep 26, 2018 at 4:47 | history | edited | Deduplicator | CC BY-SA 4.0 |
added syntax-highlighting
|
Apr 29, 2016 at 6:38 | comment | added | candied_orange | Found a decent example of code that allows A and B to be any number of lines, avoids duplicating A, and puts a test between A and B. | |
Apr 28, 2016 at 6:28 | history | bounty ended | candied_orange | ||
Apr 28, 2016 at 6:28 | vote | accept | candied_orange | ||
Apr 22, 2016 at 4:13 | vote | accept | candied_orange | ||
Apr 22, 2016 at 23:13 | |||||
Apr 19, 2016 at 18:53 | history | edited | Robert Harvey | CC BY-SA 3.0 |
added 22 characters in body
|
Apr 19, 2016 at 18:40 | history | edited | Robert Harvey | CC BY-SA 3.0 |
deleted 72 characters in body
|
Apr 19, 2016 at 18:37 | comment | added | Robert Harvey |
An example would be looking for the first occurrence of a string in each line of a text file. You would still need the while loop, but once you found the string in the line you just read, you could either break or return .
|
|
Apr 19, 2016 at 18:32 | comment | added | candied_orange | Would love to see an example. | |
Apr 19, 2016 at 18:28 | comment | added | Robert Harvey |
I'm not opposed to early exits from a loop if doing so simplifies the code. Sometimes you can just return .
|
|
Apr 19, 2016 at 18:27 | comment | added | candied_orange | That one's a classic. Would you ever suggest using a break? | |
Apr 19, 2016 at 18:25 | comment | added | Robert Harvey | See the last bit of code in my answer. | |
Apr 19, 2016 at 18:25 | comment | added | candied_orange |
Nice. There are times when you need to do A and B in order with a test T exactly between them. The usual A T(B A) priming pattern does this but duplicates A. Any general alternatives to this general pattern?
|
|
Apr 19, 2016 at 18:20 | history | edited | Robert Harvey | CC BY-SA 3.0 |
added 115 characters in body
|
Apr 19, 2016 at 18:15 | history | answered | Robert Harvey | CC BY-SA 3.0 |