When Ben found this block of code, he had some questions: who wrote it, and what was it supposed to do?

if (showOptionsButton == true)
   showOptionsButton = false;
if (showOptionsButton == false)
   showOptionsButton = true;

The genius responsible was Jim, one of the senior developers. On paper, Jim was Ben’s mentor. What was the code supposed to do?

“Well,” said Jim, “I want to toggle the state of showOptionsButton. If it’s true, it should be false, if it’s false, it should be true.”

“Except,” Ben said, “this will just always set the value to true.”

“No it won’t.”

“Yes, it will,” Ben said.

“No it won’t.”

They executed that loop a few times before Ben attempted to break out. “It will. You need an else clause.”

“If I use an else, it’ll run both clauses. I only want it to run one.”

Ben gave up on trying to correct Jim’s logic. "You could just do, showOptionsButton = !showOptionsButton.

“I’m trying to change the value,” Jim said, “not compare them. I’d love to explain the basics to you, but I really need to get this feature finished.”

Ben let his mentor get back to work.

Remy will be wandering the halls as an attendee at Tech Ed, 6/3-6/6. He'll have a stack of stickers and buttons, if you can find him. Think of it as a scavenger hunt.

[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!