Just curious if its possible. Consider follwing code:
boolean firstRow = true;
while{row = result.next())
{
if(firstRow)
{
firstRow = false;
//do some setup
}
//do stuff
}
Its pseudo-code and question is general not about some specific programming language.
My question: is it possible to write code that behaves exactly same but without using additional variable (in this case "firstRow"). In FOR loop its possible to check counter variable value but lets leave FOR loops out of this question.
Yes, do your setup before you start the loop and change it to a do..while. For example:
if (row = result.next()) {
//do some setup
do {
//do stuff
} while (row = result.next());
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With