Loop, Files refuses an opening brace on its command line

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
DiVademo
Posts: 13
Joined: 01 Jul 2019, 09:35

Loop, Files refuses an opening brace on its command line

Post by DiVademo » 26 Sep 2022, 07:45

[Moderator's note: Duplicate topic merged. Topic moved to Ask for Help.]

Hi there, with the 'new syntax' for Loop, Files, I cannot put an opening brace on the same line as the loop command.
I currently have 1.1.34.04 installed, but I had already noticed it with version 1.1.32.

The following produces an error, telling me that the closing brace } is unexpected.

Code: Select all

Loop, Files, *.* {
      command1
      command2
}
The following way is okay:

Code: Select all

Loop, Files, *.*
{
      command1
      command2
}
With the deprecated 'old syntax', where the Files keyword is omitted, I can put the opening brace on the same line. i.o.w. the following is okay:

Code: Select all

Loop, *.* {
      command1
      command2
}
If this is by design, perhaps it could be mentioned in the help file...
Cheers.

User avatar
boiler
Posts: 16709
Joined: 21 Dec 2014, 02:44

Re: Loop, Files refuses an opening brace on its command line

Post by boiler » 26 Sep 2022, 08:07

It is by design because it’s possible the file name/path could contain the { character. It is mentioned in the documentation:
{…} (block) wrote:One True Brace (OTB, K&R style): The OTB style may optionally be used in the following places: function definitions, If (expression), Else, Loop Count, While, For, Try, Catch, and Finally.

DiVademo
Posts: 13
Joined: 01 Jul 2019, 09:35

Re: Loop, Files refuses an opening brace on its command line

Post by DiVademo » 26 Sep 2022, 08:11

Okay, that makes sense. Thanks!

User avatar
boiler
Posts: 16709
Joined: 21 Dec 2014, 02:44

Re: Loop, Files refuses an opening brace on its command line

Post by boiler » 26 Sep 2022, 08:19

There is no such restriction in v2 since an opening brace character wouldn't be ambiguous (it would need to be enclosed inside a quoted string to be part of the file path), although the v2 {...} (block) documentation hasn't yet been updated to reflect that.

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Loop, Files refuses an opening brace on its command line

Post by BoBo » 26 Sep 2022, 08:22

Welcome to the wonderful world of OTB: https://www.autohotkey.com/docs/commands/Block.htm
I've requested the same about one (or maybe two) decade/s ago.

Instead of being annoyed that Loop, <whatever command> isn’t able to handle OTB, I'm doing it the other way around and using the standard loop (that would be able to handle expressions) like a command. So at least its supporting "banner style" indentation.

Code: Select all

Loop % array.Count()
   { this
     that
   }

Loop, Parse, var, CSV
   { this
     that
   }
   
Function() {
   this
   that
   }
https://handwiki.org/wiki/Indentation_style (I prefer Ratliff ;) but in case of a Loop a "Haskell'ed" Horstmann style)

safetycar
Posts: 435
Joined: 12 Aug 2017, 04:27

Re: Loop, Files refuses an opening brace on its command line

Post by safetycar » 26 Sep 2022, 11:00

I also find it annoying, but there are some remarks around for example at https://www.autohotkey.com/docs/commands/Loop.htm
And a similar note in the Legacy-If section says "The One True Brace (OTB) style may not be used with legacy If statements. It can only be used with If (expression)."
Probably not relevant to this thread, but v2 doesn't have this issues.

Post Reply

Return to “Ask for Help (v1)”