Questions tagged [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 curly brackets (or braces) "{" and "}" are special cases of brackets, along with parentheses and square brackets ("[" and "]").

Curly brackets have many uses in most programming languages, such as:

  • identify code blocks;
  • create lists and arrays;
  • pass arguments to commands in TeX.
195 questions
12
votes
7 answers

How can I extract a string between matching braces in Perl?

My input file is as below : HEADER {ABC|*|DEF {GHI 0 1 0} {{Points {}}}} {ABC|*|DEF {GHI 0 2 0} {{Points {}}}} {ABC|*|XYZ:abc:def {GHI 0 22 0} {{Points {{F1 1.1} {F2 1.2} {F3 1.3} {F4 1.4}}}}} {ABC|*|XYZ:ghi:jkl {JKL 0 372 0} {{Points…
Srilesh
  • 123
  • 1
  • 1
  • 7
9
votes
0 answers

Xcode 7: Change { (brace) location to start on a new line

I've read responses from 1, 2, and 3. I was wondering how one could do this in Xcode 7? I tried downloading Snippet Edit, but it doesn't seem to have the code for the built-in class methods stub like: override func prepareForSegue(segue:…
stumped
  • 3,235
  • 7
  • 43
  • 76
8
votes
4 answers

Why do methods with only one statement need braces?

public void Finalise() ProcessFinalisation(true); Doesn't compile, but the correct version: public void Finalise() { ProcessFinalisation(true); } Compiles fine (of course). If I am allowed if's without brackets when the following code has…
Tom Gullen
  • 61,249
  • 84
  • 283
  • 456
8
votes
6 answers

Valid Braces - CodeWars Challenge

There is a challenge on codewars that asks you to check whether a string of parentheses, brackets, and curly braces is valid. A string of braces is considered valid if all braces are matched with the correct brace. I.e. "()" is valid and "[(])" is…
HappyHands31
  • 4,001
  • 17
  • 59
  • 109
8
votes
2 answers

Difference between braces {} and brackets () in shell scripting

We use braces {} for variable expression like NAME="test" FILE_NAME=${NAME}file But I don't understand in which scenarios we use brackets () Say nslookup $(hostname) works only with () brackets. Can someone explain?
Satheesh
  • 803
  • 1
  • 11
  • 28
8
votes
1 answer

Is this valid Java code? My teacher claims it is, but I'm really not so sure

Granted he didn't show us actual code here, just mentioned it, I found it extremely bizarre. For example, according to what he said this is valid Java: public class Person { String Name; int Age; { //These two braces just…
delete
6
votes
3 answers

Can clang-format force bracing on all control statement bodies?

IE, this: if (x > 5) return test; Would always become: if (x > 5) { return test; } I'm not talking about the brace style (Allman, GNU, Whiteman, etc) I just mean having the braces there at all. There is something to prevent/enable single-line…
Tyler Shellberg
  • 1,086
  • 11
  • 28
6
votes
4 answers

What is the name of this particular indent style? ("braces stacked")

I've seen this questions here. I'm wondering if there exists an official name for the following indent style: void fooBar(String s) { while (true) { // ... do something } } When the opening brace is in the same line as the…
Ludwig Wensauer
  • 1,885
  • 3
  • 32
  • 43
6
votes
2 answers

Linked Braces in Visual Studio 2008

How can I, create a vertical line between the open brace and close brace in Visual Studio 2008 (C#), if you can't understand about what I'm talking, there's a following picture(Pic1). [Pic1 - I want to do this with the…
Rodrigo Reis
  • 1,097
  • 12
  • 21
5
votes
7 answers

Need to check that braces in given array are balanced or not

Braces in a string are considered to be balanced if they met the following conditions, All braces must be closed. braces come in a pair of the form of (), {}, []. The left brace opens the pair and the right one closes it. In any set of nested…
Bappaditya
  • 9,494
  • 3
  • 20
  • 29
5
votes
1 answer

Is it better to use braces or no braces for single-line if blocks?

What is better coding practice for single-line code blocks following an if statement - braces or no braces? Just to avoid too many "Well, it depends on what language you're using..." answers, let's say for C#. In other words, which is…
Zann Anderson
  • 4,767
  • 9
  • 35
  • 56
5
votes
1 answer

shortcut for creating braces in visual studio

many of time I have a if condition with just one line, like this: if (true) // my single code but sometimes, I want to expend my if condition to 2 or more codes, so I should use braces. if (true) { //do something } I want to know is there…
Elahe
  • 1,379
  • 2
  • 18
  • 34
5
votes
2 answers

How to jump to Next statement from For or For Each (like braces but in vb) in Visual Studio 2008

Does anyone know what the keyboard shortcut for jumping from the start of a keyword, such as for, forEach, if, while etc... is in Visual Studio when your using "vb.net"? I found the following Question, which I thought would do what I was looking…
Adam
  • 6,539
  • 3
  • 39
  • 65
5
votes
4 answers

PHP braces and conditional

What does this line mean? if ( ${fun("str1")} (fun("str2"), ${fun("str3")}) ) Evaluate function returning_value_for_str1_of_fun()_name with the parameters return value for str2 and variable with name return_value_for_str3 ?
5
votes
1 answer

Xcode Matching Pairs of Braces, Parentheses, and Brackets

If you are a notepad++ user you will understand what I want Xcode to do for me , it's very simple I want when i place the cursor before or after a Braces, Parentheses, and Brackets , it highlight for me its pair to know the matching ones juste try…
Aladin
  • 53
  • 1
  • 5
1
2
3
12 13