Skip to main content
Add example of the "pattern" and how to fix it to the answer, to make it 100% clear what's being described without needing to check the linked Daily WTF article
Source Link

The "pattern" was introduced in an earlier Daily WTF article. The basic idea is that you have a for loop with a case inside of it that selects based on the for loop index variable, e.g.:

For Icnt = 0 To 5 Select Case Icnt Case 0 DoStuff() Case 1 DoOtherStuff() Case 2 DoMoreStuff() Case 3 DoDifferentStuff() Case 4 DoYetMoreStuff() Case 5 DoFinalStuff() End Select Next 

Assuming the index variable can't be changed inside the loop, (which is not always true, depending on which language you're using,) a bit of analysis demonstrates that the execution is exactly the same as if you removed the for and the case entirely and all the case blocks were simply executed sequentially.:

DoStuff() DoOtherStuff() DoMoreStuff() DoDifferentStuff() DoYetMoreStuff() DoFinalStuff() 

The "pattern" was introduced in an earlier Daily WTF article. The basic idea is that you have a for loop with a case inside of it that selects based on the for loop index variable.

Assuming the index variable can't be changed inside the loop, (which is not always true, depending on which language you're using,) a bit of analysis demonstrates that the execution is exactly the same as if you removed the for and the case entirely and all the case blocks were simply executed sequentially.

The "pattern" was introduced in an earlier Daily WTF article. The basic idea is that you have a for loop with a case inside of it that selects based on the for loop index variable, e.g.:

For Icnt = 0 To 5 Select Case Icnt Case 0 DoStuff() Case 1 DoOtherStuff() Case 2 DoMoreStuff() Case 3 DoDifferentStuff() Case 4 DoYetMoreStuff() Case 5 DoFinalStuff() End Select Next 

Assuming the index variable can't be changed inside the loop, (which is not always true, depending on which language you're using,) a bit of analysis demonstrates that the execution is exactly the same as if you removed the for and the case entirely and all the case blocks were simply executed sequentially:

DoStuff() DoOtherStuff() DoMoreStuff() DoDifferentStuff() DoYetMoreStuff() DoFinalStuff() 
Source Link
Mason Wheeler
  • 83.3k
  • 24
  • 238
  • 312

The "pattern" was introduced in an earlier Daily WTF article. The basic idea is that you have a for loop with a case inside of it that selects based on the for loop index variable.

Assuming the index variable can't be changed inside the loop, (which is not always true, depending on which language you're using,) a bit of analysis demonstrates that the execution is exactly the same as if you removed the for and the case entirely and all the case blocks were simply executed sequentially.