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.
170 questions
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
  • 24,959
  • 33
  • 122
  • 169
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
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,267
  • 2
  • 13
  • 32
1
vote
4 answers

php braces usage

I'm not able to understand braces goal in the situation below and I find no serious documentation about braces usage. See the example below: $var = array('a','b','c','d'); foreach($var as $item){ ${$item} = array(); } I'm non…
alesdario
  • 1,643
  • 5
  • 24
  • 36
1
vote
0 answers

Why when running over a map entries then destructure is made by [] and not by {}

lets say i have the following Map: const question = new Map([ ['question', 'What is the best programming language in the world?'], [1, 'C'], [2, 'Java'], [3, 'JavaScript'], ['correct', 3], [true, 'Correct '], [false, 'Try…
Eitanos30
  • 1,089
  • 7
  • 9
1
vote
3 answers

Meaning of default init and value init?

I am very confused by c++ ways of initializing variables. What is the difference if any, between these: int i; // does this make i uninitialized? int i{}; // does this make i = 0? std::array a; // is a all zeros or all…
1
vote
0 answers

Why we have put curly-braces in for loop?

When I try to make "strcat" function for practice, I find some difference between 'for' loop with braces and without braces. But I have questions about the reason. At first, my code is like char strcat(char *ad,char *cp) { int i=0,j; …
Luke
  • 11
  • 1
1
vote
1 answer

How to display data between double braces in a set of all matches elements without using any library?

I want to make a function that can do something like this : HTML :

I am {{ name }}

{{ name }} learn JavaScript JS : data(".demo", { name: "Arc" }; Output : I am Arc Arc learn JavaScript Can…
Arcanadian Arc
  • 1,202
  • 2
  • 17
1
vote
1 answer

returning an object in JavaScript curly braces causing error

I am currently working through codecademy JavaScript course and in Objects section I found this error. Section is about factory functions and the factory function takes two parameters. Factory function returns an object when called. After return…
knight
  • 625
  • 1
  • 6
  • 19
1
vote
2 answers

How is the correct way to exapand braces in a "for loop" BASH to positional parameters?

When I try write this function in BASH function Odds () for i in {1..${#@}..2} ; do echo $i; done I expected for an output like 1 3 5... depending on number of arguments passed to the function. But the efective output is the string with ${#@}…
Daniel Bandeira
  • 332
  • 2
  • 10
1
vote
1 answer

Is there a way to fix auto indentation in netbeans, netbeans curly braces auto insert does something weird?

After pressing curly braces at the end of loop NetBeans auto indentation does this with inner for loops, in other cases works fine for (size_t j{}; j < size2; j++){ } Ending brace } doesn't align with keyword for…
1
vote
1 answer

C2447 when using braces for templated base-class initialization in templated class

I am depending on a library, the authors of which extensively used the brace-notation for invoking all constructors, as has been fondly advertised and recommended by a number of parties in recent years. The library is mostly developed on Linux using…
Pierre Schroeder
  • 414
  • 1
  • 4
  • 9
1
vote
1 answer

In java code search helper to find all places where braces is missing

Lets say I have a bunch of code and all the braces are gone like Look no braces: if(condition) statement; Yes java code convention using braces if(condition) { statement; } In particularly for Android Studio would be nice if there was a e.g.…
Erik
  • 4,514
  • 10
  • 55
  • 112
1
vote
1 answer

I didn't understand const{} in Node

const { exec } = require('child_process'); I'm still new to node.js. I would like to know what's the purpose of the curly braces near const, is it like an angular/typescript way to fetch the object from the module? Is there any ES6 or whatever new…