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
72
votes
5 answers

What is the meaning of curly braces?

Just starting to figure Python out. I've read this question and its responses: Is it true that I can't use curly braces in Python? and I still can't fathom how curly braces work, especially since pages like Simple…
JeanSibelius
  • 1,529
  • 3
  • 14
  • 27
72
votes
3 answers

What is the difference between curly brace and square bracket in Python?

what is the difference between curly brace and square bracket in python? A ={1,2} B =[1,2] when I print A and B on my terminal, they made no difference. Is it real? And sometimes, I noticed some code use {} and [] to initialize different variables.…
Haoyu Chen
  • 1,760
  • 1
  • 22
  • 32
68
votes
9 answers

Why enclose blocks of C code in curly braces?

I am looking at some C code, and have noticed it is full of these curly braces surrounding blocks of code without any sort of control structure. Take a look-see: //do some stuff . . . fprintf(stderr, "%.2f sec\n", (float)(clock() - t) /…
Jamison Dance
  • 19,896
  • 25
  • 97
  • 99
68
votes
8 answers

How to surround code by curly braces in IntelliJ IDEA?

How to surround code by curly braces in IntelliJ IDEA? Is there any keyboard-shortcut for such operation?
Pavel
  • 4,912
  • 7
  • 49
  • 69
63
votes
14 answers

PHP - If/else, for, foreach, while - without curly braces?

Something that really would like to know but never found out are shortcuts in PHP. I am currently coding a function with a foreach loop with just a single statement inside. I tried to omit the curly braces as you can do in if/else control structures…
headacheCoder
  • 4,503
  • 8
  • 30
  • 33
62
votes
5 answers

Having trouble escaping quotes and braces

I am trying to execute the following line in Command Prompt: curl -X POST -d '{ "method" : "account_info", "params" : [ { "account" : "rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh"} ] }' http://s1.ripple.com:51234 However, I get the following: curl: (6)…
killajoule
  • 3,612
  • 7
  • 30
  • 36
56
votes
4 answers

Curly braces inside JavaScript arguments for functions

What do the curly braces surrounding JavaScript arguments for functions do? var port = chrome.extension.connect({name: "testing"}); port.postMessage({found: (count != undefined)});
milan
  • 2,179
  • 9
  • 24
  • 34
54
votes
3 answers

Should I use curly brackets or concatenate variables within strings?

Is there an advantage or disadvantage to concatenating variables within strings or using curly braces instead? Concatenated: $greeting = "Welcome, " . $name . "!"; Curly braces: $greeting = "Welcome, {$name}!"; Personally, I've always concatenated…
Michael Irigoyen
  • 22,513
  • 17
  • 89
  • 131
54
votes
17 answers

Is there a difference in removing the curly braces from If statements in java

While watching thenewbostons tutorial on basic java, he teaches us to do if statements like this.(Notice the curly Braces) if("pie"== "pie"){ System.out.println("Hurrah!"); } So I tried removing the curly braces if("pie"== "pie") …
user735977
53
votes
5 answers

How to make eclipse automatically add braces to an IF statement?

In Java the following is completely valid: if (x == null) Y(); else Z(); I personally don't like it at all. I like all my IF statements to have braces: if (x == null) { Y(); } else { Z(); } The eclipse formatter is wonderful and…
Bromide
  • 1,102
  • 1
  • 10
  • 23
52
votes
4 answers

VSCode format curly brackets on the same line c#

When using the Format Document command I'd like to change how the code formats. I'm completely new to VSCode and I'm still having trouble navigating the settings, so easy to understand replies would be very helpful. Currently the code is formatting…
Gordoxgrey
  • 521
  • 1
  • 4
  • 3
48
votes
7 answers

How do you escape curly braces in javadoc inline tags, such as the {@code} tag

/** * Gets the meatball icon for a nincompoop. * *

* Example: {@code } * * @author King Cong * */ The "${person}" part breaks the doc comment because it uses curly…

user76292
47
votes
3 answers

Curly braces in "new" expression? (e.g. "new MyClass() { ... }")

What do the curly braces do there ? handler1 = new Handler() { public void handleMessage() { } }; object = new Class_Name() {}; ? This syntax exists only on Android or Java also? And what is it called in Java? Thank for your helps.
wanting252
  • 1,139
  • 2
  • 16
  • 22
46
votes
5 answers

'break' statement when using curly braces in switch-case

I use curly braces with all of my switch case statements in C/Objective-C/C++ I had not, until a few moments ago, considered whether including the break; statement inside the braces was good or bad practice. I suspect that it doesn't matter, but I…
griotspeak
  • 13,022
  • 13
  • 43
  • 54
45
votes
13 answers

Do you use curly braces for additional scoping?

I mean other than using it when required for functions, classes, if, while, switch, try-catch. I didn't know that it could be done like this until I saw this SO question. In the above link, Eli mentioned that "They use it to fold up their code in…
blizpasta
  • 2,624
  • 3
  • 25
  • 31
1
2
3
43 44