Results 1 to 3 of 3
  1. #1
    jonathan is offline Member
    Join Date
    Jul 2012
    Posts
    4
    Rep Power
    0

    Question Sentinel value and variable scope

    Does anyone know what these terms mean? I know sentinel values end a loop, but is that after we have ran the program? I would like an example. As for variable scope, I came to know it to be a variable that is only functional within the scope of its method and cannot be used within other methods. I'm not entirely sure if that's correct. If anyone could help me, that would be great, thanks!

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,423
    Rep Power
    20

    Default Re: Sentinel value and variable scope

    Quote Originally Posted by jonathan View Post
    As for variable scope, I came to know it to be a variable that is only functional within the scope of its method and cannot be used within other methods.
    What you describe is a local, or method-local, variable.

    A variable exists in the scope in which it is declared. Here 'scope' means the enclosing pair of braces { }

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,680
    Blog Entries
    7
    Rep Power
    21

    Default Re: Sentinel value and variable scope

    Quote Originally Posted by jonathan View Post
    Does anyone know what these terms mean? I know sentinel values end a loop, but is that after we have ran the program? I would like an example. As for variable scope, I came to know it to be a variable that is only functional within the scope of its method and cannot be used within other methods. I'm not entirely sure if that's correct. If anyone could help me, that would be great, thanks!
    You're talking about entirely different things here: a sentinel value is an entirely conceptual thing; if you want to implement it by a 'private static final int SENTINEL= ...' it's an implementation detail. In this example:

    Java Code:
    int x;
    while ((x= getAnInteger()) >= 0)
       doSomethingWith(x);
    The sentinel value is any negative number but no such value is explicitly present in the code.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. JSTL - How to Use request scope variable to get value from map
    By ngreddyit in forum JavaServer Pages (JSP) and JSTL
    Replies: 5
    Last Post: 01-23-2012, 07:24 PM
  2. Question about Variable Scope
    By Solarsonic in forum New To Java
    Replies: 2
    Last Post: 03-17-2011, 07:15 AM
  3. A little confused (class variable scope?)
    By Vase in forum New To Java
    Replies: 11
    Last Post: 02-03-2011, 03:51 AM
  4. variable scope between classes
    By newbie123 in forum New To Java
    Replies: 6
    Last Post: 03-04-2010, 12:20 AM
  5. Variable Scope
    By Laura Warren in forum New To Java
    Replies: 3
    Last Post: 01-11-2009, 11:16 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
  •