Hi, why do we use the break and continue structure?

Hi, I was wondering why do we use the break and continue structure in some program such as:
for ( int i = 1; i <= 10; i++ ) {
if ( i == 5 )
break;
So, now why do we use those codes, instead of achiving the same results by not using the if structure.
I am new in java so I can be totaly wrong that is why my question come to you guys.
I will appriciate if you let me understand more.

I may not completely understand your question, but - imagine the following scenario:
// Looking for some value in a long, unsorted list
Object target = null;
int index = -1;
for (int i = 0; i < list.size(); i++) {
    Object curObject = list.get(i);
    if (curObject.equals(source)) {
        target = source;
        index = i;
if (target != null){
    System.out.println("Found it at " + index);
}You will always run through the entire long list, even if the thing you are looking for is the first thing in the list. By inserting a break statement as:
// Looking for some value in a long, unsorted list
Object target = null;
int index = -1;
for (int i = 0; i < list.size(); i++) {
    Object curObject = list.get(i);
    if (curObject.equals(source)) {
        target = source;
        index = i;
        break;
if (target != null){
    System.out.println("Found it at " + index);
}You can skip whatever's left in the list.
As for continue, yes, I suppose you could use a big if, but that can get burdensome - you end up with code like:
for (int i = 0; i < list.size(); i++) {
    Object curObject = list.get(i);
    // you want to do the rest only if some condition holds
    if (someCondition) {
        // do some stuff -
        // And you end up with lots of code
        // all in this if statement thing
        // which is ok, I suppose
        // but harder to read, in my opinion, than the
        // alternative
}instead of
for (int i = 0; i < list.size(); i++) {
    Object curObject = list.get(i);
    // you want to do the rest only if some condition holds
    if (!someCondition) {
        continue;
    // do some stuff -
    // And you end up with lots of code
    // all outside of any if statement thing
    // which is easier to read, in my opinion, than the
    // alternative
}Hope that helped
Lee

Similar Messages

  • Why Cant I use the copy and paste command in elements 7.0?

    I want to create gifs using images I created, but each time I try to use the copy command (ctrl+c) after the selecting the image, It wont allow me to.It keeps saying its because of a program error. I updated it, but I still cant use the copy command?
    help me please....

    See if resetting the photoshop elements 7 preferences clears things up:
    Restore all preferences to default settings  
         Press and hold Alt+Control+Shift (Windows) or Option+Command+Shift (Mac OS) as you start Photoshop Elements. You are prompted to delete the current settings.  
    New Preferences files are created the next time you start Photoshop Elements.  

  • Why am I recently unable to use my mouse to scroll email topics or content?  I can only use the up and down arrows keys to scroll.

    Why am I recently unable to use my mouse to scroll email topics or content?  I can only use the up and down arrows keys to scroll. I am able to use my mouse to scroll through internet searches.  It only seems to have affected my email messages.

    Try a restart.
    Do a backup, using either Time Machine or a cloning program, to ensure files/data can be recovered. Two backups are better than one.
    Try setting up another admin user account to see if the same problem continues. If Back-to-My Mac is selected in System Preferences, the Guest account will not work. The intent is to see if it is specific to one account or a system wide problem. This account can be deleted later.
    Isolating an issue by using another user account
    If the problem is still there, try booting into the Safe Mode using your normal account.  Disconnect all peripherals except those needed for the test. Shut down the computer and then power it back up after waiting 10 seconds. Immediately after hearing the startup chime, hold down the shift key and continue to hold it until the gray Apple icon and a progress bar appear. The boot up is significantly slower than normal. This will reset some caches, forces a directory check, and disables all startup and login items, among other things. When you reboot normally, the initial reboot may be slower than normal. If the system operates normally, there may be 3rd party applications which are causing a problem. Try deleting/disabling the third party applications after a restart by using the application un-installer. For each disable/delete, you will need to restart if you don't do them all at once.
    Safe Mode - Mavericks
    Safe Mode - About

  • CVP: using the Gatekeeper and the SIP Proxy, why? VXML gateway and the ingress gateway communication?

    Hi All;
    I am actually keep asking with my self, why to use gatekeeper or SIP proxy when deploying the CVP solution, why not to use the Call Manager? Is it because that the concept built on SIP and H323 so call manager can not handle these kind of operations as call manager is supporting MGCP?
    From the other side, what kind of trunk or protocol of communication method is used between the ingress gateway and the VXML browser?
    Any advise?
    Regards
    Bilal

    The main reason is not all who deployed ISN/CVP in the past use Call Manager as the PBX.
    CVP is a powerful solution that covers many deployment scenarios. Its ability to integrate with legacy switches has been very important in the past, and although as we move forward, these types of deployments will probably become fewer, the independence of CVP on Call Manager remains a cornerstone of the design.
    I'm glad it was built that way. Look at some of the other deployment models (like Call Director) in the CVP Guide.
    It's not because Call Manager supports MGCP - you don't need to have any MGCP gateways in your Call Manager deployment. You could have all H.323 gateways and manage the dial plan on the gateways with a gatekeeper. Or use SIP.
    The ingress gateway does not talk to the VXML server - the VXML gateway does.
    In a branch office design, these are one and the same; but that's not the fundamental architecture. The IOS on the VXML gateway runs a voice browser (I guess you could call this a VXML browser). It uses HTTP to send and receive information (VXML documents) from the VXML server - whether this be the CVP Call Server or an external VXML server (like what was brought in-house with the Audium acqusition - the Cisco CVP VXML Server).
    Regards,
    Geoff

  • Is it possible to break an edit into small scenes, and then sew them together, but without losing quality by using the 'publish and share' options?

    Is it possible to break an edit into small scenes, and then sew them together, but without losing quality by using the 'publish and share' options?

    redflashred
    What is important here is that you know the properties of your source file(s), set the project preset to match the properties of those source files, and then export with settings as close as possible to the original. Often you can do this without noticing quality differences in the export.
    I am understanding and defining your issue as you wanting to maintain the quality of the original imported files in the export. If that is the case, the please supply the following, and I will give you a step by step
    a. What are the properties of your source files (including bitrate). Here I am looking for
    video compression
    audio compression
    frame size
    frame rate
    interlaced or progressive
    pixel aspect ratio
    file extension
    A quick way to get that type of information is knowing the brand/model/settings for the camera that recorded the video.
    2. Based on that information we can set manually a project preset to match those source property.
    3. When we go to export...example Publish+Share/Computer/ and your choice and its preset, we can customize the preset selected
    under the Advanced Button/Video Tab and Audio Tab of that preset in order to try for the best possible match between the properties of the
    original file and the properties of the export.
    But, please let us know if you also need help in trimming the original import at the Timeline level prior to export.
    Your mention of Publish+Share suggest that you are working with Premiere Elements 11, 12, or 13. What is the computer operating system?
    Thanks.
    ATR

  • Why when i use the the speaker in my i-phone 5 and i finish the call i hear strange voices ?

    why when i use the the speaker in my i-phone 5 and i finish the call i hear strange voices ?

    Another way. You can use a USB flash drive & the camera connection kit.
    Plug the USB flash drive into your computer & create a new folder titled DCIM. Then put your movie/photo files into the folder. The files must have a filename with exactly 8 characters long (no spaces) plus the file extension (i.e., my-movie.mov; DSCN0164.jpg).
    Now plug the flash drive into the iPad using the camera connection kit. Open the Photos app, the movie/photo files should appear & you can import. (You can not export using the camera connection kit.)
    Secrets of the iPad Camera Connection Kit
    http://howto.cnet.com/8301-11310_39-57401068-285/secrets-of-the-ipad-camera-conn ection-kit/
     Cheers, Tom

  • I have 100's of CDs that I have downloaded to my itunes library and they are in the library playable but they do not show up in the C drive under the iTunes Music folder under users.  Why are they in the libary and not in the itunes music folder. Win 7 OS

    I have 100's of CDs that I have downloaded to my itunes library and they are in the library playable but they do not show up in the C drive under the iTunes Music folder under users.  Why are they in the libary and not in the itunes music folder. Win 7 OS.  When I look in the library under the get info screen it says they are in the folder itunes music, under the c: drive but when I actually go to that folder to look for them they are not there....HELP!

    Hello RumDog,
    I think this article will help you find the media in your library.
    Where are my iTunes files located?
    http://support.apple.com/kb/ht1391
    Discovering and changing the iTunes Media folder location
    Note: You would usually only change the iTunes Media folder location to share music between accounts on the same computer. See this article for specific steps on how to accomplish this. Also, see this article if you want to know how to move your music to a new computer.
    Mac OS X: Click the iTunes menu and choose Preferences.
    Windows: Click the Edit menu and choose Preferences.
    Click the Advanced pane. iTunes displays the location of your iTunes Media folder.
    You can then:
    Note where your media folder is, such as for backing up your media.
    Use the Reset button to reset it's location to the default (which is the iTunes folder).
    Click the Change button to select a folder for a new location. Once you change this location:
    If you make a new or alternate iTunes library, the new location will be used by that library.
    Existing files will not be moved unless you choose File > Library > Organize library and choose the option to "Consolidate files."
    From: Where are my iTunes files located?
              http://support.apple.com/kb/ht1391
    Cheers,
    Sterling

  • IPad2 and a new MacBook running Lion, Both Devices use the same Apple ID which is a Hotmail eMail id. Can I create a new iCloud eMail Id and use iCloud eMail and continue to use my Hotmail Id for my Apple Id and use it for iTunes, iCloud

    I have an iPad2 and a new MacBook running Mountain Lion. Both Devices use the same Apple ID which is a Hotmail eMail id. Can I create a new iCloud eMail Id and use iCloud eMail and continue to use my current Hotmail Id for my Apple Id for iTunes, iCloud.
    Note, I will use both Hotmail and iCloud eMail.

    Welcome to the Apple Community.
    In order to change your Apple ID or password for your iCloud account on your iOS device, you need to delete the account from your iOS device first, then add it back using your updated details. (Settings > iCloud, scroll down and hit "Delete Account")

  • I have bought an used Iphone 5. I dont have the password for the existing login id of the old owner. How do i use the phone and change the log in id?

    I have bought an used Iphone 5. I dont have the password for the existing login id of the old owner. How do i use the phone and change the log in id?

    Unfortunatly the only way that you can get it off is to get the old user to input the password.  You may need to contact that old user and see if he can put the old password in.  hope this helps.

  • I am new to iMovies.  When I make a video using the mic and camera in my Macbook Pro, the audio and video are not in synch.  Very annoying.  How can I fix this?

    I am new to iMovies.  When I make a video using the mic and camera in my Macbook Pro, the audio and video are not in synch.  Very annoying.  How can I fix this?

    DVD drives read the bottom of the disk, not the top. Smooth out the paper & try again.

  • I have an iphone 4, i connect it to my laptop using the usb and then when connecting to itunes it says my phone is not up to date with itunes yet i cannot find an update 11.1 for my phones itunes? someone please help me.. kind regards

    i have an iphone 4, i connect it to my laptop using the usb and then when connecting to itunes it says my phone is not up to date with itunes yet i cannot find an update 11.1 for my phones itunes? someone please help me.. kind regards

    Itunes 11.1 is for your computer, not your iphone
    It is required in order to sync with ios 7.

  • The application does not use the  screen and run in the background

    Hi
    I have downloaded a package of j2me Midlet
    from [link] here [link]
    and try to reuse the code
    but I get the following error when running the code:-
    The application does not use the screen and run in the background
    I think the error into one of these two classes
    package main;
    import javax.microedition.midlet.*;
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.media.Manager;
    import javax.microedition.media.MediaException;
    import javax.microedition.media.Player;
    import java.io.IOException;
    import java.io.InputStream;
    public class MainMidlet extends MIDlet implements CommandListener {
        private SSGameCanvas gameCanvas ;
        private Command exitCommand ;
        private Player player = null;
        public void startApp() {
      try {
           //   create new game thread
              gameCanvas = new SSGameCanvas();
              gameCanvas.start(); // start game thread
              exitCommand = new Command("Exit",Command.EXIT,1);
              gameCanvas.addCommand(exitCommand);
              gameCanvas.setCommandListener(this);
                Display.getDisplay(this).setCurrent(gameCanvas);
       catch (java.io.IOException e)
                e.printStackTrace();
            try {
                // start sounds
                InputStream in = getClass().getResourceAsStream("/resource/startfly.wav");
                player = Manager.createPlayer(in,"audio/x-wav");
                player.setLoopCount(1);
                player.start();
            catch (MediaException ex)
                ex.printStackTrace();
             catch (IOException ex)
                ex.printStackTrace();
        public void pauseApp() {
        public void destroyApp(boolean unconditional) {
            if (player != null) {
                player.close();
            System.gc();
      public void commandAction(Command command, Displayable displayable) {
           if (command == exitCommand)
                 destroyApp(true);
                 notifyDestroyed();
    package main;
    import java.io.IOException;
    import javax.microedition.lcdui.*;
    import javax.microedition.lcdui.game.*;
    public class SSGameCanvas extends GameCanvas implements Runnable {
        protected GameManager gameManager;
        protected boolean running;
        private int tick=0;
        private static int WIDTH;
        private static int HEIGHT;
        private int mDelay = 20;
        Form mainForm;
        Display display;
        //private int MaxTime;
        public SSGameCanvas() throws IOException{
            super(true);
            gameManager = new GameManager(5,5,getHeight()-10,getWidth()-10,this);
        public void start() {
                this.running = true;
                Thread t = new Thread(this);
                t.start();
        public void stop() {
            running = false;
        public void render(Graphics g) {
            WIDTH = getWidth();
            HEIGHT = getHeight();
            // Clear the Canvas.
            g.setColor(0, 0, 50);
            g.fillRect(0,0,WIDTH-1,HEIGHT-1);
            // draw border
            g.setColor(200,0,0);
            g.drawRect(0,0,WIDTH-1,HEIGHT-1);
            // draw game canvas
            gameManager.paint(g);
        public void run() {
            while (running) {
                // draw graphics
                render(getGraphics());
                // advance to next graphics
                advance(tick++);
                // display
                flushGraphics();
                try { Thread.sleep(mDelay); }
                catch (InterruptedException ie) {}
        public void advance(int ticks) {
            // advance to next game canvas
            gameManager.advance(ticks);
            this.paint(getGraphics());
    }Edited by: VANPERSIE on Jul 10, 2012 12:26 PM

    Hi Andi,
    Thanks for your reply.
    Yes, I have waited for a while and the result doesn't change.
    The Porblem here is the application is seen started in visual administrator.Only restart brings up the page back.
    Can you please suggest anything.
    Thanks and regards
    Nagaraj

  • How can I use the "Copy and paste" tool in order get stamps in the same position in different pages (Acrobat XI for PC)?

    With Acrobat 6.0 I was able to copy a stamp in the same position (I mean "exactly" the same one) of different pages just by using the "copy/past" tool.
    Now I am using Acrobat XI and it seems like it is not possible anymore: I am copying a stamp and I am trying to past it in anoter page, but it appears in the center of the page (or wherever it wants to...).
    Does anyone have a solution?
    Thanks in advance.

    Thank you very much. I'll be waiting for you message.
    Messaggio originale----
    Da: [email protected]
    Data: 26/01/2015 17.56
    A: "Umberto Gangi"<[email protected]>
    Ogg:  How can I use the "Copy and paste" tool in order get stamps in the same position in different pages (Acrobat XI for PC)?
        How can I use the "Copy and paste" tool in order get stamps in the same position in different pages (Acrobat XI for PC)?
        created by Gilad D (try67) in Creating, Editing &amp; Exporting PDFs - View the full discussion
    Well, I was in the same situation so I've developed a tool that allows one to do it. I will send you some additional information about it in a private message.
         If the reply above answers your question, please take a moment to mark this answer as correct by visiting: https://forums.adobe.com/message/7132586#7132586 and clicking ‘Correct’ below the answer
         Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page:
    Please note that the Adobe Forums do not accept email attachments. If you want to embed an image in your message please visit the thread in the forum and click the camera icon: https://forums.adobe.com/message/7132586#7132586
         To unsubscribe from this thread, please visit the message page at , click "Following" at the top right, &amp; "Stop Following"
         Start a new discussion in Creating, Editing &amp; Exporting PDFs by email or at Adobe Community
      For more information about maintaining your forum email notifications please go to https://forums.adobe.com/thread/1516624.

  • My MacBook Pro is running very slow when using the internet and sometimes gives the pinwheel of death, any suggestions on how to fix?

    My MacBook Pro is running very slow when using the internet and sometimes gives the pinwheel of death, any suggestions on how to fix?

    <http://www.thexlab.com/faqs/sbbod.html>

  • How do I use the counter and digital signals of the 6071E while it is connected to SCXI modules?

    I am contemplating using a PCI 6071E with SCXI. We have the boards (6071E), we would need the cable (I suppose SH1006868) and the SCXI system. I would like to know how would you access the counter and digital line capabilities of the board. I will be using a SCXI-1314 with a SCXI-1520 Module for strain measurements but will need to use the counter and digital lines of the board as well. Can this be done? If so, how and/or what else do I need?

    I think this KnowledgeBase will answer the question for you.
    Accessing DAQ Board Counter Pins with an SCXI System
    Otis
    Training and Certification
    Product Support Engineer
    National Instruments

Maybe you are looking for