c# - Do Loop, an efficient break method? -


i have section inside method similar too:

do {     // query      // query      if query != null     {         // return     }  }while(some query != null) 

obviously not work, because query not declared until inside loop. 1 solution tried

bool flag = false; {     // query      if query == null     {         flag = true;         // or          break;     }      // query      if query != null     {         // return     }  }while(flag != true) 

neither method satisfies me, , quite not sure if considered coding practice, irks me. has pretty has been go solution in cases until point, due garbage nature of flag, wanted find out if there better way handle future reference, instead of making junk variable. should note other solution thought of arguably uglier. solution being run query once outside loop, , convert while loop , recall query again inside itself, rather loop.

while code works above solution, wondering if had better solution not require arguably pointless variable.

though understand such better solution may not possible, or needed, ridiculous try.

having break or flag variable isn't make inefficient, it's inside loop should concern. in other words it's preference , either fine.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

inno setup - TLabel or TNewStaticText - change .Font.Style on Focus like Cursor changes with .Cursor -