Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6924171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:37:44+00:00 2026-05-27T10:37:44+00:00

When I started developing, I followed tutorials that always used {} (curly braces) to

  • 0

When I started developing, I followed tutorials that always used {} (curly braces) to enclose blocks. However, when I began looking at other peoples code (classes on GitHub for example, or just more code in general than what a basic tutorial would show), however I’ve also seen block statements without being enclosed in {}, for example;

if($var < 15)
     $string = 'Hello, Jimmy!';
elseif($var >= 15)
     $string = 'Hello, Anne!';

Is the same as

if($var < 15) { 
    $string = 'Hello, Jimmy!';
} elseif($var >= 15) {
    $string = 'Hello, Anne!';
}

I’ve never used blocks not enclosed in {}, however I used them today and I’m starting to see the efficiency of doing so (it looks a lot cleaner too, as I’ll often find my functions riddled with {} from loops, conditionals etc.

What I’m asking is;

a) are there any limitations on blocks without curly braces (; I noticed my IDE dropped back from an indent after I enter a single line and returned after an if() conditional?

b) are there any best practices to be had, when not using {}?

Any answers, specifically those inc. background/docs on the convention of curly brace usage for blocks vs. not using them would be greatly appreciated, as I’d really like to understand the usage of curly braces :)!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T10:37:45+00:00Added an answer on May 27, 2026 at 10:37 am

    You can omit the {} for one single line:

    if(something)
      do something else
    

    however you cannot omit it and have it keep going like so:

    if(something)
       do one thing
       do another
       do some more
    

    The example above would only have 1 conditional element (the ‘do one thing’). The rest would just run unconditionally.

    And yes I’ve seen the sloppy method before without the {}, I myself prefer using {} to separate the logic, and its easier to read.

    So stick to using {} in your code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I started developing my application in AppEngine Java, however I noticed that Facebook has
I started developing an iPhone application in June 2010 that used the Facebook APIs
I started developing an application in Silverlight that was dealing with downloading the HTML
Our team has just started developing for the Sitecore CMS. We find that after
HI all, I'm just getting started with developing for Android. I'm looking to port
i started developing apps in Titanium,in that i have already set android sdk path
I'm getting started developing for the iPhone and as such I am looking at
I've started developing a site that pulls two images randomly from a database. I
I've recently started developing applications for the Blackberry. Consequently, I've had to jump to
I've recently started developing my first serious application which uses a SQL database, and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.