0

I'm looking at the excel exploit that can bypass the sheet protection in a matter of seconds. They use a nested for loop similar to the first code snippet i was wondering if

This:

For i = 65 To 66: For j = 65 To 66: For k = 65 To 66
    'code'   
Next: Next: Next:

is the same as this:

For i = 65 To 66
    For j = 65 To 66
         For k = 65 To 66
              'code'
         Next
    Next
Next

Any help is appreciated.

Dan13_
  • 193
  • 1
  • 2
  • 16
  • 1
    Yes, `:` can typically be used instead of a new line. – Alex K. Jun 13 '16 at 16:02
  • make it a answer and i will accept it if you want. – Dan13_ Jun 13 '16 at 16:03
  • 2
    replace 'code' by `debug.print i, j, k` run both, and you will know. – iDevlop Jun 13 '16 at 16:04
  • 2
    Also worth noting if you are using Excel 2013 (or newer) this macro won't work since they've changed their sheet security. See an answer [here](http://stackoverflow.com/questions/37334365/password-cracker-of-protected-sheet-in-excel-using-vba/37334705#37334705). – gtwebb Jun 13 '16 at 16:18

1 Answers1

1

It's the same. One little difference though - the bottom snippet makes the nesting explicit.

The top snippet makes the code's indentation lie about its real nesting level, and violates an important coding principle:

[...] Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. Code for readability.

source

That code is basically "golfed" to be as short as possible, and to avoid looking like the outright ugly arrow code it really is.

Community
  • 1
  • 1
Mathieu Guindon
  • 69,817
  • 8
  • 107
  • 235