Results 1 to 3 of 3

Thread: brackets

  1. #1
    aussieguy0101 is offline Member
    Join Date
    Feb 2013
    Posts
    4
    Rep Power
    0

    Default brackets

    Hi All
    I have been studying java for a short time at night school, one thing I dont understand in java especially loops is the { and } brackets and when to use them
    I know the ( is used after declaring the class name but Im confused as to how to use them in loop
    is there an easy explanation of these?

    thanks!

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,787
    Blog Entries
    7
    Rep Power
    21

    Default Re: brackets

    Curly brackets are used for grouping other elements of the Java language; e.g. if you want more than one statement to be executed when an if-condition happens to be true, you have to do this:

    Java Code:
    if (<condition>) {
       // execute all this
    }
    Similar with, say, for loops;

    Java Code:
    for (<init>; <condition>; <increment>) {
       // execute all this
    }
    or while loops:

    Java Code:
    while (<condition>) {
       // execute all this
    }
    The stuff between < ... > is a general form for actual Java expressions; curly brackets are a syntactic language issue only; other languages use 'begin' and 'end' for '{' and '}' but Java uses the latter because C (a very terse language) uses them. Other languages (Python comes to mind) don't use any of them; the indentation is supposed to denote the grouping of other language elements. You'll get used to those brackets; just practice ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    aussieguy0101 is offline Member
    Join Date
    Feb 2013
    Posts
    4
    Rep Power
    0

Similar Threads

  1. split square brackets [].
    By mhye in forum New To Java
    Replies: 5
    Last Post: 01-06-2011, 02:33 PM
  2. Rotate Text Inside Brackets
    By corbokhan in forum New To Java
    Replies: 1
    Last Post: 10-16-2010, 02:01 AM
  3. use of <> brackets
    By dqlevitt in forum New To Java
    Replies: 3
    Last Post: 05-27-2010, 10:34 PM
  4. Arrowhead brackets
    By dushmantha.e in forum New To Java
    Replies: 5
    Last Post: 02-14-2010, 10:08 AM
  5. Bracket help - can't find the missing brackets.
    By Z E P H Y R in forum New To Java
    Replies: 0
    Last Post: 03-17-2009, 11:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •