Questions tagged [curly-braces]

The symbols "{" and "}", commonly used in programming languages. Please use this tag only if the specific usage of these symbols is a relevant part of the question.

The symbols "{" and "}", commonly used in programming languages. Please be sure that the specific usage of these symbols is a relevant part of the question.

652 questions
2427
votes
23 answers

How do I escape curly-brace ({}) characters in a string while using .format (or an f-string)?

Non-working example: print(" \{ Hello \} {0} ".format(42)) Desired output: {Hello} 42
Schitti
  • 25,489
  • 8
  • 24
  • 21
956
votes
7 answers

When do we need curly braces around shell variables?

In shell scripts, when do we use {} when expanding variables? For example, I have seen the following: var=10 # Declare variable echo "${var}" # One use of the variable echo "$var" # Another use of the variable Is there a significant…
New User
  • 9,759
  • 4
  • 15
  • 8
598
votes
28 answers

Go to Matching Brace in Visual Studio?

Is there a way in Visual Studio 2008 to go from a closing brace to its opening brace? I've found a fair amount of stuff about highlighting the brace, but nothing about moving the cursor to it. (VB.NET version of this Question: Keyboard shortcut for…
thepocketwade
  • 6,436
  • 5
  • 22
  • 25
400
votes
7 answers

Eclipse jump to closing brace

What is the keyboard short cut in Eclipse to jump to the closing brace of a scope?
Trastle
  • 5,155
  • 6
  • 26
  • 20
340
votes
24 answers

What's the purpose of using braces (i.e. {}) for a single-line if or loop?

I'm reading some lecture notes of my C++ lecturer and he wrote the following: Use Indentation // OK Never rely on operator precedence - Always use parentheses // OK Always use a { } block - even for a single line // not OK, why ??? Const object…
JAN
  • 21,236
  • 66
  • 181
  • 318
292
votes
1 answer

How to escape curly-brackets in f-strings?

I have a string in which I would like curly-brackets, but also take advantage of the f-strings feature. Is there some syntax that works for this? Here are two ways it does not work. I would like to include the literal text {bar} as part of the…
JDAnders
  • 4,831
  • 4
  • 10
  • 8
175
votes
15 answers

Is it a bad practice to use an if-statement without curly braces?

I've seen code like this: if(statement) do this; else do this; However, I think this is more readable: if(statement){ do this; }else{ do this; } Since both methods work, is this simply a matter of preference which to use or would…
jerebear
  • 6,503
  • 4
  • 31
  • 38
166
votes
3 answers

SyntaxError: not a chance — What is this error?

I tried to execute the following code on a Python IDLE from __future__ import braces And I got the following error: SyntaxError: not a chance What does the above error mean?
Anurag-Sharma
  • 4,278
  • 5
  • 27
  • 42
144
votes
11 answers

Format Curly Braces on Same Line in C++ VSCode

I'm using the C++ Extension for VSCode (Visual Studio Code). Currently, I have the setting "C_Cpp.clang_format_formatOnSave" set to true. This format's my code when I save my C++ file. But the format results in curly braces on new lines rather than…
Ari Seyhun
  • 11,506
  • 16
  • 62
  • 109
101
votes
8 answers

List of all Unicode's open/close brackets

What is a list of every Unicode bracket-like characters (including, for example: {}[]()<>)? What is a good way to search for Unicode characters?
MaiaVictor
  • 51,090
  • 44
  • 144
  • 286
85
votes
4 answers

Can I make Visual Studio place curly braces on the same line as an if statement (in HTML)?

In Visual Studio while designing MVC views (in .aspx or .ascx files), I often use if statements. When I auto-format (Ctrl+K+D), Visual Studio wraps the braces in this really ugly and hard to read way: <% if (Model.UserIsAuthenticated) { %> …
Mike Comstock
  • 6,640
  • 10
  • 36
  • 41
85
votes
11 answers

What do curly braces in Java mean by themselves?

I have some Java code that uses curly braces in two ways // Curly braces attached to an 'if' statement: if(node.getId() != null) { node.getId().apply(this); } // Curly braces by themselves: { List copy = new…
Paul Wicks
  • 62,960
  • 55
  • 119
  • 146
82
votes
4 answers

C# Switch statement with/without curly brackets.... what's the difference?

Has C# always permitted you to omit curly brackets inside a switch() statement between the case: statements? What is the effect of omitting them, as javascript programmers often do? Example: switch(x) { case OneWay: { …
makerofthings7
  • 60,103
  • 53
  • 215
  • 448
82
votes
5 answers

PHP curly brace syntax for member variable

First question on SO and it's a real RTM candidate. But I promise you I've looked and can't seem to find it. I'll happily do a #headpalm when it turns out to be a simple thing that I missed. Trying to figure out Zend Framework and came across the…
David Weinraub
  • 14,144
  • 4
  • 42
  • 64
78
votes
4 answers

What is the meaning of the ${0##...} syntax with variable, braces and hash character in bash?

I just saw some code in bash that I didn't quite understand. Being the newbie bash scripter, I'm not sure what's going on. echo ${0##/*} echo ${0} I don't really see a difference in output in these two commands (prints the script name). Is that…
user215997
  • 1,267
  • 2
  • 12
  • 12
1
2 3
43 44