Skip to main content
Post Closed as "Duplicate" by gnat, CommunityBot, psr, Dan Pichelman
Tweeted twitter.com/#!/StackProgrammer/status/497233768756039680
edited tags; edited title
Link
Tulains Córdova
  • 39.6k
  • 13
  • 102
  • 157

Dependencies Eliminate duplicate code in ifs?nested IFs without creating a function

Source Link
Mikayla Maki
  • 603
  • 1
  • 5
  • 14

Dependencies in ifs?

Let's say we have two ifs that depend on each other:

if var exists {
    if var is array {
        //Do stuff with var
    } else {
        //Resolve the problem
    }
} else {
    //Resolve the problem in the exact same way as above
}
//Continue execution with the assumption that var is in the appropriate state

How can I refactor this to remove the duplicated code without using gotos or functions/methods?