Refactor (C) pseudo code to remove goto
Tag : java , By : user105769
Date : March 29 2020, 07:55 AM
it helps some times You first want to determine what the code is trying to accomplish: Do the following over and over: Call try_something() up to MAX_ATTEMPT times, restarting if it never returns true. Call try_next_thing() up to MAX_ATTEMPT times, restarting if it never returns true. while (true) {
int i;
for (i = 0; i < MAX_ATTEMPT && !try_something(); ++ i)
;
if (i == MAX_ATTEMPT)
continue;
for (i = 0; i < MAX_ATTEMPT && !try_next_thing(); ++ i)
;
if (i == MAX_ATTEMPT)
continue;
// etc.
}
boolean doFirstThing () {
int i;
for (i = 0; i < MAX_ATTEMPTS && !try_something(); ++ i)
;
return i < MAX_ATTEMPTS;
}
boolean doSecondThing () {
int i;
for (i = 0; i < MAX_ATTEMPTS && !try_other_thing(); ++ i)
;
return i < MAX_ATTEMPTS;
}
// then, elsewhere
while (true)
doFirstThing() && doSecondThing();
|
How to remove 'goto' from this loop?
Tag : cpp , By : user112141
Date : March 29 2020, 07:55 AM
seems to work fine You can just set an extra bool condition to break outer for loop. You can also simplify your inner loops when you notice that they are essentially the same, just invoke different match3 functions: while(gameCards.size() > 2)
{
auto continue_outer_loop(true);
for(unsigned int i2=1; continue_outer_loop && (i2<gameCards.size()); i2++)
{
if(i2 == 2) continue;
auto const p_match_3_func
(
cannotMatch(gameCards.at(i1), gameCards.at(i2))
?
&cannotMatch3
:
&canMatch3
);
for(unsigned int i3=2; i3<gameCards.size(); i3++)
{
if((*p_match_3_func)(gameCards.at(i1), gameCards.at(i2), gameCards.at(i3)))
{
SetMatches++;
gameCards.erase(gameCards.begin()+i2,gameCards.begin()+i3);
continue_outer_loop = false;
break;
}
}
}
gameCards.erase(gameCards.begin()+(i1++));
}
|
How best to remove all UIViewcontrollers and goto a single UIViewController?
Tag : ios , By : Terrence Poon
Date : October 14 2020, 08:10 PM
help you fix your problem I have an application with the option to change a users password. The reset password process is all done via web links. When the process is complete, the user returns to their app. Given that the password has now been changed, i would like to log the user out. , Make sure you have to run the UI events on main thread. DispatchQueue.main.async {
let loginVC = self.storyboard?.instantiateViewController(withIdentifier: "login") as! MyLoginViewController
self.present(loginVC, animated: true, completion: nil)
}
|
Remove goto/switch stataments after using ILSpy
Tag : chash , By : kameel
Date : March 29 2020, 07:55 AM
|
How do I remove 'goto' here
Tag : chash , By : Frank Bradley
Date : March 29 2020, 07:55 AM
|