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
2
votes
1 answer

Lone braces inside a class?

I couldn't find anything about this online, because I didn't know what to search for, but Java doesn't mark this code as having an error: public class Test { // ... { int test; } // ... } Does this serve any purpose in…
2
votes
2 answers

brace after else on same line in spite of changing it in formatter

I would like to have my else as follows else { } However, at the moment it still looks like else { } I have gone and edited the Braces tab in Window -> Preferences -> Java -> Code Style -> Formatter and changed everything to Next line.…
tubby
  • 2,074
  • 3
  • 33
  • 55
2
votes
2 answers

In Vi, navigate / jump to the brackets around the current block

Supposing we have some code: var f = function(a) { var g = {"b" : "c", "m" : "n" // cursor is here "d" : "e", "h" : { "i" : "j", "k": "l" }, "m" : { …
Rene Wooller
  • 1,107
  • 13
  • 22
2
votes
1 answer

Elasticsearch term query with colons

I have a string field "title"(not analyzed) in elasticsearch. A document has title "Garfield 2: A Tail Of Two Kitties (2006)". When I use the following json to query, no result returns. {"query":{"term":{"title":"Garfield 2: A Tail Of Two Kitties…
Leon Kennedy
  • 63
  • 3
  • 6
2
votes
1 answer

Is there a principle for writing messages with java MessageFormat to avoid the error caused by escape braces or quote?

I meet a problem using MessageFormat among several projects. In a base project, we use the Message Format to build warning message like: Exception for a char ({0}). In another project, I use the base project to do something and will log the…
paco alcacer
  • 381
  • 2
  • 13
2
votes
2 answers

PyParsing Parse nested loop with brace and specific header

I found several topics about pyparsing. They are dealing with almost the same problem in parsing nested loop, but even with that, i can't find a solution to my errors. I have the following format : key value; header_name "optional_metadata" { …
user1130
  • 1
  • 4
2
votes
1 answer

How do I indent lines with vim when there are commented-out braces?

I usually use the vim re-indent operator ('=') in order to indent my sourcecode according to its syntax. I also use it on the whole file, especially if I have to read sourcecode that was written by someone else and they have different tab settings…
Viktor Dick
  • 111
  • 2
2
votes
8 answers

Why do I get a compiling error that says error: ‘else’ without a previous ‘if’?

When I try to compile the code I get an error that says else without a previous if: // Fibonacci series using recursion #include using namespace std; int fib (int n); int main() { int n, answer; cout << "\n\n\t\tEnter number…
lowriderzxxx
  • 163
  • 8
2
votes
4 answers

regular expression for content within braces

is there a regular expression to match the content within braces. For example with the following: d = {'key': {'a': [1,2,3]}} I would want to match {'key': {'a': [1,2,3]}} and {'a': [1,2,3]}, but not {'key': {'a': [1,2,3]}
hoju
  • 28,392
  • 37
  • 134
  • 178
1
vote
2 answers

PHP include top file and bottom file containing ifelse curly braces

How can I include_once a php file at the top that contains an if statement with an open curly brace, And then include a file at the bottom that contains the closing curly brace to that if statement with more if statements preceding it?
jonnypixel
  • 327
  • 5
  • 27
1
vote
0 answers

C# VsCode doesn't put braces in new line

The problem is whenever i try to type i.e. a method() then put "{" and "enter" to make both braces go below the method (in new line) then only one goes down and the first stays on the right side of the method. I've tried every step from these…
Vandal
  • 21
  • 2
  • 6
1
vote
1 answer

Brace expansion in zsh - how to concatenate two lists for file selection?

In zsh, one can create an expression of {nx..ny}, for example to select files x to y inside a folder. For example, {1..50} selects items, files, etc. from 1 to 50. How can I concatenate two two brace expansions into one? Example: I would like to…
Philipp
  • 335
  • 2
  • 4
  • 12
1
vote
1 answer

How to change the color of braces in JSX & TSX in Intellij 2022.3

I just updated to version 2022.3 of Intellij Ultimate, and the color for braces in jsx/tsx code blocks has turned to yellow, but I want to revert it to the original color.enter image description hereIn this image, the curly braces around the values…
1
vote
3 answers

C consecutive(not nested) one-liner for loops not iterating properly

Final Edit When debugging this code, I would see the first loop line execute n times, but the following lines would execute only once. Only later I would notice that the expected value changes, though, were in fact being made: it was just the loop…
101is5
  • 309
  • 2
  • 12
1
vote
2 answers

Bash not comparing strings properly

This is my bash file #!/bin/sh ENV=DEV echo "env: $ENV" if [[ "$ENV" == DEV* ]]; then RUNTIME_CLASSPATH=$(cat ../build/dev.classpath) echo "cp: $RUNTIME_CLASSPATH" fi echo "done" And here's the terminal output: ~proj/bin$ ./test.sh env:…
Kevin
  • 1,080
  • 3
  • 15
  • 41