What are Curly Brackets in Programming?

We’ve all seen them before. They’re the symbols that look like this: {}. When you see an opening curly bracket, it usually means something’s starting or beginning to happen. That’s because they are used in programming code to tell a computer what to do at that point of the program.

Curly brackets are also called as open brace and close brace, and squiggly brackets. Curly brackets are found on the same keys as open and close brackets on any US keyboards.

How to Type Curly Brackets

On a US keyboard, open and close curl bracket keys lie on the same place as open adn close bracket keys. So you can use Shift + Bracket to type in respective curly bracket.

How are Curly Brackets Used in Programming?

Curl brackets are used in computer programming to enclose any sets of instructions that should be grouped together. For example, they can contain a list or sequence of commands for the program to execute one byone from top to bottom. They can also be used as containers for variables and lists of values where each item is separated with a comma or semicolon.

Curly brackets, also known as curly braces or simply braces in some programming languages, are key which encloses groups of statements. They’re typically used to close off code blocks and can be very helpful when searching out errors with complex strings by reducing the number of lines.

Example of Curly Brackets Used in PHP

//loop
foreach ($pages as $page) {
    echo $page->title;
}

//a class
class Student {
    public $name;
    public $hometown;

    function longName() {
        return $name + ' - ' + $hometown;
    }
}

//function 
function convertData($source){
	$output = $source;
	if($source > 0 && $source < 0.1){ $output = 0.1; };
	if($source > 0.1 && $source < 0.2){ $output = 0.2; };
	if($source > 0.2 && $source < 0.3){ $output = 0.3; };
	if($source > 0.3 && $source < 0.4){ $output = 0.4; };
	if($source > 0.4 && $source < 0.5){ $output = 0.5; };
	if($source > 0.5 && $source < 0.6){ $output = 0.6; };
	if($source > 0.6 && $source < 0.7){ $output = 0.7; };
	if($source > 0.7 && $source < 0.8){ $output = 0.8; };
	if($source > 0.8 && $source < 0.9){ $output = 0.9; };
	if($source > 0.9 && $source < 1){ $output = 1; };
		
	return $output;
}

Leave a Comment

Your email address will not be published. Required fields are marked *


Scroll to Top

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close