Question on Loop

Why is it when I try to print num, it cannot find symbol, but when I use while loop it can?
public class ForLoop {
     public static void main (String[] args) {
          int sum=0;
          for (int num=0; num<10; num++) {
               sum+=num;
          System.out.println(num);
          System.out.println("Total: "+sum);
}

ashok.kulhari wrote:
num variable is local variable for a LOOP block only and outside it cannot be access.Really? Gee I wish I had said that in my first reply.
</sarcasm>

Similar Messages

  • Few questions - game loop, data types, speed

    Hello, I have a few questions after studying some topics in this forum regarding game creation:
    1) What's the fastest way to wait in the game loop? I've seen two approaches:
    thread.sleep(10)andsynchronized(this) { wait(10); }2) What data types shall I use? In C++ I use to prefer int over short in all cases, because 32bit hardware works faster with integers. Is this same on cell phones?
    3) Speed of applications is slow. I just wonder wheter it's my fault. I was testing application, which only cleared the buffer and outputted FPS and I got around 20 frames. It was Nokia 6300 with 240x320 display. After testing on other phones I've found out that the bigger the resolution, the slower the game is going. Is this normal?
    Thanks for replies...

    1) You're not going to notice any really speed difference between the two code snippets. Read up on 'Threads', and you'll see why one may be used in place of the other depending on the situation. In general there may be a slight performance loss, however unnoticable, when using the synchronized version, but when you are multithreading it is likely necessary.
    sleep(int) is impossible to interrupt, so it's generally a no-no in most situations. However we are talking about devices where every bit of performance helps, so as long as it works for ya, it's not a big deal.
    2) The performance difference is fairly negligable, if any. The biggest thing to consider is memory requirements, and shorts take 1/2 the data.
    Also, many phones don't support floating point data types, so you'll likely need to use ints/longs to calculate your values if you want to have any accuracy beyond whole numbers. Doing something like shifting bits or using 1000x values in your calculations can get around most of the problems when you can't use floats.
    3) The biggest performance killers are IO, memory allocation, screen drawing; pretty much in that order. So I imagine that you are re-creating a new String object every time you output your FPS value on screen right? Doing that every frame would destroy any hopes of getting high-performance.
    Just be careful, and never allocate objects when you can avoid it. anything where you concat String objects using + will cause your performance to die a horrible painful slow death. Remove anything that says 'new' from your main loop, and all String operations, and it'll likely speed things up a lot for ya.
    Does your main loop have something like this?
    g.drawString("FPS: " + currentFps, 0,0,Graphics.TOP | Graphics.LEFT);
    This is very bad because of the String operation. It'll create a new String every frame.
    If you have any more specicif questions, or you'd just like to pick the brain of a mobile game dev, stop by my messageboard:
    http://attackgames.proboards84.com
    Message was edited by:
    hooble

  • Performance question on looping thrue blocks and items (forms 10.1.2.3)

    Hi all,
    I'm back again in Forms forum : ) !!! and I'm working on a new and very interesting project
    version used : Forms [32 bits] Version 10.1.2.3.0 (Production)
    A little question for gurus :
    On former projects I used to call loops on blocks and item like shown below to do various things such as displaying buttons or showing canvas or different VA depending on the user or scenarios .
    PROCEDURE FRM_BLK_ITM_LOOP IS
    v_curblk varchar2(90); -- bloc courant
    v_curitm varchar2(90); -- item courant
    BEGIN
      v_curblk := get_form_property(:SYSTEM.CURRENT_FORM,first_block); -- on récupère le 1er block de la form
      LOOP
      v_curitm := v_curblk||'.'||get_block_property(v_curblk,first_item); -- on récupère le 1er item du block
        WHILE v_curitm != v_curblk||'.'||get_block_property(v_curblk,last_item)
         LOOP -- tant que l'item n'est pas le dernier du block on loop
            v_curitm :=  v_curblk||'.'||get_item_property(v_curitm,nextitem); -- on récupère l item suivant
            if get_item_property(v_curitm,<some property>) = 'TRUE' then
              --- I can do something.... or adding more conditions if then etc...
            end if;
        END LOOP;
      EXIT WHEN v_curblk = get_form_property(:SYSTEM.CURRENT_FORM,last_block); -- on sort losrqu on arrive au dernier block
      v_curblk := get_block_property(v_curblk, nextblock); -- on passe au block suivant
      END LOOP;
    END;In my current project we work on quite huge forms which can have a consequent number of blocks and items.
    And we must be very careful regarding performance issues as these forms are accessed via LAN and WAN.
    So my question :
    This method seems to be quite efficient as it goes thrue blocks and items sequences as they are defined in the builder comparing to go_block -> go_item ->do_something which can easily turn into nightmare-programming.
    But I don't really know about network roundtrips with this kind of method.
    Is everything done in the app server and then fetched to the client?
    What triggers block-level and item-level can be fired during the execution of the loop ? and so one...
    Thanks in advance for your advices on this matter.
    Jean-Yves

    Hmmm, I have to say I never bothered if Forms is in Socket mode or not; I enabled the network statistics, counted the roundtrips and looked for ways to get them lower (my old friend wireshark did also a good job regarding this) ;). But regarding the note Forms 6i uses Socket Connections by default, this might apply to 10g too (or the enhancement request was approved, who knows).
    Frankly I am not entirely sure what Socket Mode means; I guess it's the mode the forms applet talks to the forms runtime; wheter it's stateful (via Sockets) or stateless (via HTTP / HTTPS) but this is just a wild guess, and I can't find informations on it quickly. I also enabled networkStats on my Developer Suite only, so I cannot tell if you can enable them on a full-fledged Application Server.
    Anyway; as said I just counted the roundtrips and looked where I can avoid them when I made our application ready for WAN.
    Another useful tool was Shunra VE Desktop which I used to simulate low bandwith networks with high latencys; I installed it on a virtual XP, started the application and tested how the Application performs. If something looked odd, I looked behind the scenes, built a little testform basing on the code behind and tried out various things; very often you can take advantage of the event bundling forms seems to make when you use several set_xyz calls as Francois also noted; e.g.
    set_custom_property('bean_item', 1, 'PROPERTY', prop);
    set_custom_property('bean_item', 1, 'PROPERTY', prop);
    set_custom_property('bean_item', 1, 'PROPERTY', prop);
    set_custom_property('bean_item', 1, 'PROPERTY', prop);
    set_custom_property('bean_item', 1, 'PROPERTY', prop);
    vRet := get_custom_property('bean_item', 1, 'PROPERTY);most certainly will cause just 1 roundtrip; but if you use get_custom_property in the middle of the set_custom_property calls you will encounter 2 roundtrips as forms needs to synchronize (you get a value from the bean so the forms runtime needs a response) with the forms applet whereas set_custom_property is a one-way-street which can be fired off simultaneous. The same applies to fbean.invoke and fbean.invoke_bool, fbean.invoke_char and the like. Of course if you are using more then one get_custom_property in this case the roundtrips will increase accordingly.
    If you want to make use of event bundling make sure you fire off as much set_xyz as you can before forcing forms to synchronize (e.g. with get_xyz, or synchronize, create_timer,...)
    cheers

  • Questions on looping

    Hi all experts of iDVD,
    I have burn the video in iDVD. My movies are set to loop. So, as expected the movie keeps looping. But how do I get back to the selection page ?
    I press STOP but it doesn't go back to the selection page & it gives me a blank page.
    I have to press EJECT & EJECT again to place the video in, then only will I be able to see the Selection page.
    So when I set the video to loop, how do I get back to the selection page ?
    Thanks

    Captivate 8 introduced the common JavaScript API which gets and sets Captivate variables for both SWF and HTML5 output in the same way.  You can read more about that here:
    https://helpx.adobe.com/captivate/using/common-js-interface.html
    Another great thing about Captivate 8, is that they exposed Captivate events to JavaScript.  So, for example, you can listen for when a user submits a quiz question and execute your own JavaScript when that submit event occurs.  Not only can you listen for this event, you also get information sent to you about that event... like what the correct answer was vs. what the student chose.  What I'd recommend is that you subscribe to the following events:
    CPAPI_QUESTIONSUBMIT
    CPAPI_INTERACTIVEITEMSUBMIT
    The event data sent back from the event will give you the information you need.  Download the sample project from the article to find out how to subscribe to these events.

  • Basic Questions about Looping and Headers

    Hello,
    Relative SSRS newcomer here and I have a couple of foundational questions...  These are based on the simple premise of the underlying dataset returning multiple rows of data, elements of each to be displayed on subsequent pages of the report.
    Is it fair to day that the Table (or Matrix) are the basic elements used for an iterative report?
    Assuming the above is true, I'm using a Table for my first experiment here.
    I can iterate and display my records but I'm struggling with header and footer information.
    I want to display header and footer information on each page the is part of the current record.  I've tried to add these elements in the 'header row' of the table, but that doesn't seem to do it.  I don't see any facility for a footer.  Is
    this to be accomplished with row groups or something?
    Any guidance would be appreciated.

    Hi Steven,
    According to your description, you want to display interview questions and answers between interview name and date, and different interview name displays in different page. After testing the issue in my environment, we can use list to achieve your goal.
    Please refer to the following steps:
    Add a table to the design surface, drag question_name, question_answer fields from the Report Data pane to the table cells, and delete the last column of the table.
    Click anywhere in a tablix data region, in the Grouping pane, Click Add Group, select Parent Group, in the Tablix Group dialog box, select interview_name, then click OK. 
    Right click [interview_name] next to details symbol, click insert row, select Inside Group – Below, then Inside Group – Above.
    Delete the first row and the first column.
    Merge all the cells in the first and last row, then drag interview_name to the first row and drag interview_date to the last row from the Report Data pane. 
    Add a List to the design surface, drag the tablix into the List.
    Select and right click the List, in the Grouping pane, Click Group Properties, click Add button and select interview_name from the drop down list. Then click Page Breaks, and check Between each instance of a group check box, click OK.
    The following screenshot is for your reference:
    If you have any more questions, please feel free to ask.
    Thanks,
    Wendy Fu

  • AS 101 question on loops

    I'm stuck on something that's really fundamental and it's
    driving me nuts.
    I've got five buttons labeled "btn_1", "btn_2", etc. When a
    button is pressed, I'd like to trace it's corresponding number.
    When I try this:
    for(var i:Number=1;i<6;i++){
    this["btn_"+i].onPress = function(){
    trace(i);
    ... it traces "6" regardless of which button is pressed. I
    know I'm missing a variable somewhere, but my grey matter's crapped
    out. Help? Many thanks in advance.

    yeah this is common with loops of this nature - because the
    'last' number iterated to is 6 so the value of i is now 6 once the
    loop completes. to remedy, store the current value of i in a
    property of the btn instance then call that prop as in:

  • Security question infinite loop.  How to break it?

    My account rescue email address was set to an unauthorized address.  The unauthorized user reset the security questions. 
    To change the security questions, you have to have the correct answers, OR the rescue address.
    To change the rescue address, you have to have the security question answers.
    There seems to be no way to fix this, and I've been trying for 20 minutes to find a phone number for account support, can't find it.

    You might try contacting Apple through iTunes Store Support

  • Question about loops

    hey guys,
    with this piece of code here... right now I have it reading a dataSet and printing out the first Value out of 9 datapoints. How can I tweak this so that it would read through ALL 9 datapoints. I know i can do a loop but im not sure how to go about it!...
    int numDataSets = dc.size(); // determine number of data sets in collection
          for (int i=0; i<numDataSets; i++) {
            dataSet ds = dc.get(i); // get the ith dataset
            String  filename = ds.sourceFileName;
            System.out.println("the number of DataSets: " + numDataSets);
            dataEl  el = ds.get(0); // get the 0th element of the ith dataset
            double value = el.getMainValue(); // get the associated main value
            int dateInt = el.getDateInt();
            //for (int dateInt=0; dateInt<0; dateInt++) {
            System.out.println("data set " + filename + ": value " + value + dateInt);
          }

    You'd use a nested loop. It's no trouble to nest one loop inside another. Traditionally, if i is the index variable of the outer loop, then j is the index variable of the inner one.
    By the way, if dc is a java.util.Collection (saying that it's a java.util.Collection means that it's a class that implements that interface, or implements a sub-interface of that interface), and if you're using JDK 1.5 or above, then you don't need to use an explicitly indexed for loop. You could just do this:
    for(dataSet ds : dc) {
        // your code here
    }And you could easily nest a similar loop inside of that.

  • Quick question about looping movie clips

    I'm a REAL Flash novice, and I'm trying to get a movie clip to loop 3 times, and then continue on.
    Here's the code I've written (I'm sure it's painful to see)
    stop();
    if (!loopCount) {
      var loopCount:Number = 0;
    loopCount++;
    if (loopcount < 3) {
    gotoAndPlay (1)
    if (loopCount = 3) {
      gotoAndPlay(363);
    Could someone help me out?
    Thanks,
    Brandon

    use double equal (==) to test for equality:
    stop();
    if (!loopCount) {
      var loopCount:Number = 0;
    loopCount++;
    if (loopcount < 3) {
    gotoAndPlay (1)
    if (loopCount == 3) {
      gotoAndPlay(363);

  • Question about Looping through tables in Adobe Form

    Hello,
    We have an adobe form which is to be filled offline. It consists of a table. Table can have repeating rows and user can add\remove rows as they wish.  The cardinality of the context node where we need to bind this table data is set to 1…n
    We want to know the process to get all the values in the table back into our context node once the form is uploaded. I assume we need to loop through the table, and add elements to the context node.  Can someone please let us know if we’re on the right track, and provide some sample code if possible?
    <b>We can’t figure out a way to loop through a table inside an Adobe form.</b>
    We are using Web Dynpro Java with Adobe Livecycle Designer 7.1
    Your help is much appreciated.
    Thanks,
    Rob.

    Try using...
    for (z = 0; z < 16; z++) {
         this["cb"+z].setStyle("styleName", "cssCBstyle");
    That is the way to target them.  I haven't dealt with setting styles, so I can't answer for that aspect working or not.

  • Questions reg Looping through a Node inside a Currently Selected Node.

    i have the following context structure in my WD application.
    Parent Customer Node  A<Cardinality 1.n & Selection 1.n & Singleton True>
          Child Addresses Node B<Cardinality 1.n & Selection 1.n & Singleton True>
                  Child Attribute B.City
          Child Attribute A.Name
          Child Attribute A.Age
    For the currently selected Parent Customer Element, i want to read the all the addresses this customer has. How to read all the addresses of the customer and loop through it & show it.
    Any inputs are appreciated.

    Hello Saravanan,
    Please use the Singleton Concept.
    Refer the following links.
    http://help.sap.com/saphelp_nwce711core/helpdata/en/47/be673f79c8296fe10000000a42189b/frameset.htm
    http://wiki.sdn.sap.com/wiki/display/WDJava/SupplyFunctionin+Webdynpro
    http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/60086bd5-9301-2b10-6f97-a14366a5602b/
    if you have doubt in implementation then let us know.
    Regards
    Nizamudeen SM

  • Newbie question about looped querys

    Hi there!
    I'm starting in this thing of CF dev .
    My question is the next;
    I have a table with 2 foreign keys and want to order my
    result this way :
    a
    1
    name surname etc,etc
    name surname etc,etc
    2
    name surname etc,etc
    3
    name surname etc,etc
    name surname etc,etc
    name surname etc,etc
    b
    1
    name surname etc,etc
    name surname etc,etc
    2
    name surname etc,etc
    name surname etc,etc
    and so on ...
    a and b belong to foreign_key_1
    1 and 2 belong to foreign_key_2
    oneof my try codes for the query is the next one :
    select foreign_key_1,foreign_key_2,name, surname,etc...
    order by foreign_key_1 group by foreign_key_2
    thank you in advance!

    Use the group attribute of cfoutput. The cfml reference
    manual has a excellent example. If you don't have one, the internet
    does.

  • VideoDisplay and events question and looping the video?

    i have a flex ap that starts a video via a button click, i also have an event handle to detect when the video is finished
    code sample below
    private function loadandstartvideo(event:Event):void
              var thisvideo:VideoDisplay = VideoDisplay.getChildbyName("thisvid")
              thisvideo.removeevent(event.Complete,videoDisplay)
              thisvideo.source = "path/to/vid/"
              thisvideo.addeventListen(event.complete,restartvid)
              thisvideo.play();
    private function restartvid(event:Event):void
              var thisvideo:VideoDisplay = VideoDisplay.getChildbyName("thisvid")
              thisvideo.play()
    the above code is not the exact code the problem i have is that the loadandstart switched the video just fine but the restartvid function never gets called?
    anyone have a clue? if you need the exact code i can post it.

    here is the actual code. i poisted the other post from a different computer...
    playinto is the function called from the button click
    private function playintro(boardID:Number):void
            introIndex = boardID;
            var boxid:Number = boardID - 1;
            var vidBoxName:String = "hwsVid" + String(boardID);
            var vidBox:VideoDisplay = VideoDisplay(HWSDisplay.getChildByName(vidBoxName));
            vidBox.source = "path to vid;
            tempWidth = vidBox.width;
            tempHeight = vidBox.height;
            tempX = vidBox.x;
            tempY = vidBox.y;
            vidBox.x = 0;
            vidBox.y = 0;
            vidBox.height = Number(disHeight.text)
            vidBox.width = Number(disWidth.text)
            vidBox.maintainAspectRatio = false;
            var tempVidBox:VideoDisplay = new VideoDisplay;
            var tempBoxName:String = "";
            var a:Number;
            for (a=1;a<10;a++)
                    if (a != boardID)
                            tempBoxName = "hwsVid" + String(a);
                            tempVidBox = VideoDisplay(HWSDisplay.getChildByName(tempBoxName));
                            tempVidBox.visible = false;
            vidBox.addEventListener(Event.COMPLETE,onIntroComplete)
            vidBox.play()
    private function onIntroComplete(event:Event):void
            var vidBox2:VideoDisplay = VideoDisplay(event.currentTarget);
            vidBox2.removeEventListener(VideoEvent.COMPLETE,onIntroComplete)
            vidBox2.source = "path to loop vid;
            vidBox2.x = tempX;
            vidBox2.y = tempY;
            vidBox2.height = tempHeight;
            vidBox2.width = tempWidth;
            vidBox2.addEventListener(VideoEvent.COMPLETE,restartVidLoop)
    private function restartVidLoop(event:VideoEvent):void
            var vidBox:VideoDisplay = VideoDisplay(event.currentTarget);
            vidBox.removeEventListener(Event.COMPLETE,restartVidLoop);
            vidBox.addEventListener(Event.COMPLETE,restartVidLoop);
            vidBox.play();

  • Question: for loop

    Hi, can anyone tell me why am I get a error message when I
    click on the link? I checked the XML file is fine and images are
    loaded properly except when I click the links which comes up an
    error message that cannot find the URL. Thanks!

    assuming you've run trace() functions and the urls appear to
    be correct, you probably have white space (usually carriage
    returns) at the end of the url.
    you can check the length of one of your urls to confirm. to
    remedy, strip the white space using the flash string
    methods.

  • Question in switching for STP and loop

    hi ,
    i have a question in loop issue , will it occur in this case or not
    i will describe my scenario as below :
    now i have 4 switches connected with full mesh.
    =================
    3 of them has stp protocol enabled
    only 1 of them is un manged and dont support STP protocol
    ====================================
    the question is :
    if i connected the 4 switches full mesh  , will  the loop occurs ??
    as i believe , stp loop prevention depend on the switch itself not on their neighbour ,  but not sure from my understanding
    wish to help
    regards

    Disclaimer
    The Author of this posting offers the information contained within this posting without consideration and with the reader's understanding that there's no implied or expressed suitability or fitness for any purpose. Information provided is for informational purposes only and should not be construed as rendering professional advice of any kind. Usage of this posting's information is solely at reader's own risk.
    Liability Disclaimer
    In no event shall Author be liable for any damages whatsoever (including, without limitation, damages for loss of use, data or profit) arising out of the use or inability to use the posting's information even if Author has been advised of the possibility of such damage.
    Posting
    If there's only one or two non-STP switches, in a full mesh, you'll be okay.  Once you have at least three non-STP switches, in a full mesh, you have a loop between them.

Maybe you are looking for

  • RFC error text: timeout during allocate / CPIC-CALL: 'ThSAPCMRCV'

    I am having this error pop up very frequently on some new SAP systems.  This will randomly happen and keep us from being able to release transports and import them in STMS.  I receive the following error: There was an attempt to start the transport c

  • Fault tolerance in Weblogic

    I am working on the Servlet and EJB based architecture on WebSphere Application server. The application has stringent Fault Tolerance requirement i.e. if the http/application server goes down then also the users are not effected. I will appreciate an

  • When I try to cut and paste my resume into an online job website the reume' will not highlight ( select All), any ideas?

    When I try to cut and paste my resume' into an online job website it will not highlight, ( select all), I can click and drag it into the empty box but then it becomes an  attachment. What am I doing wrong?  Help!

  • Download error message 50 Help

    I have tried to download several times and keep getting error messages saying check my connection - I am on a high speed connection. Then they start downloading again but they are duplicating what I already tried to download.

  • IPhoto '08 won't save photos

    After installing iPhoto '08 over the previous version, which was working properly, I can't seem to save the photos I download from my camera. I get this message: "Some recent changes may be lost. Make sure your hard disk has enough space and that iPh