While loop not breaking?

I'm writing a parser for some text files.
My setup looks like so:
public void parseFile(String fileNameIn) throws IOException{
        BufferedReader br = new BufferedReader(
                new FileReader(fileNameIn));
        String line = null;
        line = br.readLine();
        while(line != null){
            //do a bunch of stuff
            line = br.readLine();
}I hit a line that == null when I am parsing and for some reason it is not breaking out of the while loop? I have no idea why.

Sch104 wrote:
I hit a line that == null when I am parsingNo, you don't. That condition causes control to exit from the loop when it reaches the end of the file. A line of text can't be null. Perhaps it might contain zero characters, or only white space, but that doesn't make it null. If you want to break out of the loop when you reach an empty line, you'll have to write a test for an empty line.
(Don't worry about what ibanezplayer85 said. Your code is perfectly good for processing a text file, it's equivalent to what he/she posted. I think your version is easier to understand, but you will very frequently encounter his/her version in code so it doesn't hurt to understand it, though.)

Similar Messages

  • Trouble with while loop, not sure what to put in it in my project

    I'm making a class to a simple command line craps game. I must use a while loop to implement craps rules. The rules that i was given are:
    if your first roll is a 4, 5, 6, 8, 9, or 10, you roll again until either you get a 7 (you lose) or you get the number from your first roll. (i thought 7 or 11 wins, like in the next example)
    yeah, thats right, not very good directions. The first directions i had for a different way of doing it using if and else statements were:
    The player rolls the two dice.
    If the sum of the resulting die values is 7 or 11, the player wins.
    If the sum is 2, 3, or 12, the player loses.
    If something else is rolled, the player has to roll again to determine the outcome.
    If the sum of the second roll is the same as what the player rolled the first time, the player wins. Otherwise the player loses.
    (You might get a pair of dice and play a few rounds to try it.)
    here's my code that i have so far for my craps class, in the middle section, i have previous code that i used for if else statements, that is what im trying to replace: package games;public class Craps {
    private Dice dice1;
    private Dice dice2;
    private int gamesPlayed;
    private int gamesWon;
    private boolean lastGameWon;
    private boolean gameOver;
    private int firstRoll;
    private int secondRoll;
    public Craps() {
    dice1 = new Dice(6);
    dice2 = new Dice(6);
    gamesPlayed = 0;
    gamesWon = 0;
    lastGameWon = false;
    firstRoll = 1;
    secondRoll = 2;
         //returns firstroll
    public int getFirstRoll(){
    return firstRoll;
         //returns secondroll
    public int getSecondRoll(){
    return secondRoll;
    public int getGamesPlayed(){
    return gamesPlayed;
    public int getGamesWon(){
    return gamesWon;
    public boolean lastGameWon(){
    return lastGameWon;
         public int nextSum()
         dice1.roll();
         dice2.roll();
         return dice1.getSideUp() + dice2.getSideUp();
    public void play()
              firstRoll = nextSum();
    if (firstRoll == 7 || firstRoll == 11)
              gameOver = true;
              gamesWon++;
              if (firstRoll == 2 || firstRoll == 3 || firstRoll == 12)
              gameOver = true;
                   else{
                   gameOver = false;
              while (gameOver == false)
              secondRoll++;
    public String toString()
    return "games - " + gamesPlayed + ", won - " + gamesWon + ", last game won - " + lastGameWon + " First Roll - " + firstRoll +
    ", Second Roll - " + secondRoll;
    i'm really confused on how to get the while loop will keep starting the game over if it is false, am i using the right approach? Also i have to use a while loop, its for a school project.
    thanks.

    The code you asked for could be:
    package games;
    public class Craps {
        private Dice dice1;
        private Dice dice2;
        private int gamesPlayed;
        private int gamesWon;
        private boolean lastGameWon;
        private boolean gameOver;
        private int firstRoll;
        private int secondRoll;
        public Craps()
            dice1 = new Dice(6);
            dice2 = new Dice(6);
            gamesPlayed = 0;
            gamesWon = 0;
            lastGameWon = false;
            firstRoll = 1;
            secondRoll = 2;
         //returns firstroll
        public int getFirstRoll(){
            return firstRoll;
         //returns secondroll
        public int getSecondRoll(){
            return secondRoll;
        public int getGamesPlayed(){
            return gamesPlayed;
        public int getGamesWon(){
            return gamesWon;
        public boolean lastGameWon(){
            return lastGameWon;
        public int nextSum()
            dice1.roll();
            dice2.roll();
            return dice1.getSideUp() + dice2.getSideUp();
        public void play() {
            gamesPlayed++;
            firstRoll = nextSum();
            if (firstRoll == 7 || firstRoll == 11)
                gamesWon++;
                lastGameWon = true;
            else if (firstRoll == 2 || firstRoll == 3 || firstRoll == 12)
                lastGameWon = false;
            else
               secondRoll = nextSum();
               if (firstRoll == secondRoll)
                  gamesWon++;
                  lastGameWon = true;
               else
                  lastGameWon = false;
        public String toString()
            return "games - " + gamesPlayed + ", won - " + gamesWon + ", last game won - " + lastGameWon + " First Roll - " + firstRoll +
                    ", Second Roll - " + secondRoll;
    }I'm not sure of craps rules, the code above makes a first roll and if game isn't won or lose at once (7 and 11 wins, 2,3 or 12 lose) a second roll is done. If the second roll is equals to the first made then the game is won else the game is lose. Is it right?

  • While loop not performing correctly

    When I enter ANY number, the second while loop in the code below executes. It should not execute when 117, 239, 298, 326, or 445 is entered. I can't seem to figure out why this does not work, and I do not know what else to try.
    Hope someone can just give some assistance. Thank you!
    If I need to supply the entire program, just let me know.
    while(! done)
                   try
                        System.out.println("Enter the flight number");
                        entry = keyboard.nextInt();
                        while((entry != 117) || (entry != 239) || (entry != 298) || (entry != 326) || (entry!= 445))
                             System.out.println("Flight number must be 117, 239, 298, 326, 445");
                             System.out.println("Please try again");
                             entry = keyboard.nextInt( );
                             done = true;
                   catch(InputMismatchException e)
                        keyboard.nextLine();
                        System.out.println("Not the correct entry");
                        System.out.println("Please try again");
              }

    JosAH wrote:
    paulcw wrote:
    The outer loop loops on "not done", but in the body of that loop, done is unconditionally set to true. So the outer loop will only run once. Therefore it's pointless. I'm guessing that you meant to only set done to true if the user inputs "quit" or something.The 'not done' loop will iterate again if the user supplied incorrect input (not an int).Man that's a confusing flow of control. So if the user types in anything other than a number, it's causes a parse error (basically) and the exception causes it to skip the command to stop, and that makes it loop again.
    So apparently 3/4 of the people looking at that code didn't get it at first.
    It reminds me of the veda about Mel.
    Come up with something clearer.

  • Parallel while loops not running in parallel

    I am collecting data from a PCI 4351 board and a 6070E board. These are connected to a TC 2190 and a BNC 2090. I do not need exact sychronization, however I do need them to collect data at different rates. Currently I am using two while loops to perform this, but they run sequentially in stead of simultaneously, that is, the second while loop waits for the first one to finish before running. Is there any way I can get these to run both at the same time instead of one after the other?
    Attachments:
    Parallel Whiles.vi ‏89 KB

    Any way you do it, you're going to have to sequentially read from the data buffer, and the implementation you have now may be the fastest, if not the most accurate.  I would recommend that you either put a wait statement in each loop if the two data reads need different timing, or just wire the error cluster from one's output to the other's input and have them both in the same loop.  At least that way you are always certain which is executing before the other.  Also, in the dataflow (wired together) example, I would still recommend a wait statement, just to be on the safe side.  Even if you have a wait of 10 ms it may save you from spinning your loop pointlessly.
    =============
    XP SP2, LV 8.2
    CLAD

  • Why does my While loop not work?

    I was using the SetInterval timer but this kept causing problems getting the timing right,
    So I thought - get the loop to work infiitely...
    var cond=0;
    while (cond !=1){
    $("#DivStage1").fadeIn(1000);
    $("#DivStage1").delay(6500).fadeOut(500); //8000
    $("#DivStage1_1").show("slide", {direction:'left'}, 1000);
    $("#DivStage1_1").delay(6500).hide("slide", {direction:'left'},500);
    $("#DivStage1_2").delay(1000).show("slide", {direction:'left'}, 1000);
    $("#DivStage1_2").delay(5500).hide("slide", {direction:'left'}, 1000);
    $("#DivStage2").delay(8000).fadeIn(1000);
    $("#DivStage2").delay(17000).fadeOut(500); //8000 to 16000
                            $("#DivStage2_1").delay(8000).show("slide", {direction:'left'}, 1000);
                             $("#DivStage2_1 h2 #1 style='color: #FFF;'").show();
                             $("#DivStage2_1").delay(16000).hide("slide", {direction:'left'},500);
    The page does not execute the loop.
    Thanks in advance for any feedback

    Create a function for the loop and call the function when the document is ready.
    Don't forget to include the jQuery library, jquery.js or similar.

  • While loop not terminating

    hmm. very strange to me. i have a condition that if a person enters QUIT then the program should terminate but for some reason its not terminating.
    import java.util.*;
    class BicycleTest {
         public static void main(String[] args) {
              BNode start, tail, next;
              start = null;
              Scanner s = new Scanner(System.in);
              System.out.println("Enter name");
              String name = s.next();
              if(!name.equalsIgnoreCase("QUIT")) {
                   start = new BNode(new Bicycle(name), null);
                   tail = start;
                   while(true) {
                        name = s.next();
                        if(name.equalsIgnoreCase("QUIT")) break;
                        next = new BNode(new Bicycle(name), null);
                        tail.setNext(next);
                        tail = next;
    }

    jverd when you say an older version that means the
    java version or the compiler? No, an older version of your code. Like you changed it (to what you first posted) but forgot to save or recompile. Maybe before you had equals instead of equalsIgnoreCase, or something like that.

  • Re: exit from a while loop in sub vi

    I think the mail didn`t get through first time. Repeat posting - Sorry if
    this occurs twice
    Shane
    Hallo,
    Can the use of occurrences solve this problem?
    The Main program can create an occurrence which can be passed to the
    sub-VIs. Upon pressing the button to cancel the loop, the occurrence can be
    set, instantly transmitted to all other VIs sharing which were passed the
    same occurrence. Of course a small handling routine has to be written (say
    a sequence parallel to the executing while loop waiting for the occurrence
    and then setting the exit parameter to "true") but this is trivial.
    I have checked this with a small program splitting an occurrence to three
    seperate VIs and it works.
    If you want, I can send a cop
    y of it.
    It may well be possible with notifiers or something else, but I have far
    less experience with them.
    Hope this helps
    Shane
    >pcu schrieb in Nachricht
    ><[email protected]>...
    >>Main vi has several sub-vi's. Each sub vi has a while loop and Boolean
    >>button. When program runs, sub-vi front panel appears, and I can
    >>stop/continue the while loop. But when I stopped a while loop in a
    >>sub-vi, I cannot control other while loops in other sub vi.
    >>I need exit function from a while loop, not stop function of entire
    >>program.
    >>Thanks.
    >
    >
    Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)

    The notifier is probably better than occurence at this case - than it is not neccessry to write a parallel sequence.
    The use of notifier is very simple, just follow an example in Help/Search example -> Advances -> Execution control -- Synchronization -> SubVI notification.
    Good luck
    Ferda

  • Exit from a while loop in sub vi

    Main vi has several sub-vi's. Each sub vi has a while loop and Boolean button. When program runs, sub-vi front panel appears, and I can stop/continue the while loop. But when I stopped a while loop in a sub-vi, I cannot control other while loops in other sub vi.
    I need exit function from a while loop, not stop function of entire program.
    Thanks.

    Hallo,
    Can the use of occurrences solve this problem?
    The Main program can create an occurrence which can be passed to the
    sub-VIs. Upon pressing the button to cancel the loop, the occurrence can be
    set, instantly transmitted to all other VIs sharing which were passed the
    same occurrence. Of course a small handling routine has to be written (say
    a sequence parallel to the executing while loop waiting for the occurrence
    and then setting the exit parameter to "true") but this is trivial.
    I have checked this with a small program splitting an occurrence to three
    seperate VIs and it works.
    If you want, I can send a copy of it.
    It may well be possible with notifiers or something else, but I have far
    less experience with them.
    Hope this helps
    Shane
    pcu schrieb in Nachr
    icht
    <[email protected]>...
    >Main vi has several sub-vi's. Each sub vi has a while loop and Boolean
    >button. When program runs, sub-vi front panel appears, and I can
    >stop/continue the while loop. But when I stopped a while loop in a
    >sub-vi, I cannot control other while loops in other sub vi.
    >I need exit function from a while loop, not stop function of entire
    >program.
    >Thanks.
    Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)

  • Can not pass data after while loop

    Hello.
    I have created a VI for my experiment and am having problem passing data outside a while loop to save on an excel file. The VI needs to first move a probe radially, take data at 1mm increment, then move axially, take data radially at 1mm increment, then move to the next axial position and repeat. It would then export these data to an excel file. The VI is a little complicated but it's the only way I know how to make it for our experiment. I have tested it and all the motion works correctly, however I can not get it to pass the data after the last while loop on the far right of the VI where I have put the arrows (Please see the attached VI ). Is it because I'm using too many sequence, case, and while loops?  If so, what other ways can I use to make it export data to the excel file?
    Any help would be appreciated. 
    Thank you,
    Max
    Attachments:
    B.Dot.Probe.Exp.vi ‏66 KB

    Ummmm .... gee, I'm not even sure where to begin with this one. Your VI is well .... ummmm... You have straight wires! That's always nice to see. As for everything else. Well... Your fundamental problem is lack of understanding of dataflow programming. What you've created is a text program. It would look fantastic in C. In LabVIEW it makes my heart break. For a direct answer to your question: Data will not show up outside a while loop until the while loop has completed. This means your most likely problem is that the conditions to stop that specific loop are not being met. As for what the problem is, I don't even want to start debugging this code. Of course, one way to pass data outside of loops is with local variables, and hey, you seem to be having so much fun with those, what's one more?
    This may sound harsh, and perhaps be somewhat insulting, but the brutal truth is that what I would personally do is to throw it out and to start using a good architecture like a state machine. This kind of framework is easy to code, easy to modify, and easy to debug. All qualities that your code seems to lack.
    Message Edited by smercurio_fc on 08-17-2009 10:00 PM

  • Can't break out of a while loop

    Hi, I am doing a networking course, for which an assignment was to write an echo client and server. I did the assignment in Java and it works just fine. However, there is something I don't understand that is bugging me. I wanted a way to stop the server by either detecting when the client entered "quit" or when the user of the server entered "quit". This was not part of the assignment, but after trying many different things I really want to know (1) what I am doing wrong and (2) what the correct way to do things would be.
    I tried to put an "if" clause within the while loop so that if the client entered "quit" the server would detect that, close the socket connections, and break the while loop. But... it seems that I have done this wrong and I am not sure why.
    (Note - I am not a Java programer - just a beginner, and the course in question isn't a programming course. I did the program below by following some brief guidelines/tutorial. I don't even have any books on Java to consult right now - just ordered few from Amazon for any future projects.)
    The code:
    // EchoServer.java     - a simple server program. It listens on a predetermined port for an incoming connection.
    //                After a client connects they can input a line of text and
    //                the server will echo the exact same line back.
    import java.io.*;
    import java.net.*;
    public class EchoServer {
         protected static int DEFAULT_PORT = 3004;
         public static void main (String args[]) throws Exception {
              int portNumber;          
              try {
                   portNumber = Integer.parseInt(args[0]);
              } catch (Exception e) {
                   portNumber = DEFAULT_PORT;
              ServerSocket myServer = null;
                try{
                   myServer = new ServerSocket(portNumber);      
                   System.out.println("Echo Server started. Listening on port " + portNumber);
              } catch (IOException e) {
                   System.out.println("Could not listen on port: " + portNumber);
                   System.out.println(e);
              Socket clientSocket = null;                         
              try{          
                     clientSocket = myServer.accept();
              } catch (IOException e) {
                     System.out.println("Accept failed:  " + portNumber);
                   System.out.println(e);
              BufferedReader input = null;     
              PrintWriter output = null;
              try {               
                   input = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
                   output = new PrintWriter(clientSocket.getOutputStream(), true);
              } catch (IOException e) {
                   System.out.println(e);
              String theLine;     
              while(true){
                   theLine = input.readLine();
                   output.println(theLine);     
                   output.flush();
                        if (theLine.equals("quit"))  {
                             input.close();
                             output.close();
                             clientSocket.close();
                             myServer.close();     
                             break;
                        }     // end if
              }     // end while     
         }     // end main
    }          // end EchoClient

    A few observations:
    - You might as well exit after you have caught your exceptions, since none of the conditions I see would allow your program to run properly afterwards. You can either do that by a System.exit(int) or a return;
    - Although this s an example program, you should take advantage of doing things right. Addining a try-finally would be good for tidying things up. First declare your variables before the main try, otherwise the finally won't be able to do its job. For example (this won't compile as is):
    Socket clientSocket = null;
    ServerSocket myServer = null;
    InputStream in = null;
    OutputStream out =null;
    try {
      String theLine = null;     
      while( (theLine = input.readLine()) != null ){
        output.println(theLine);     
        output.flush();
        if (theLine.equals("quit"))  {
           break;
      }     // end while
    } catch ( IOException ex ) {
      ex.printStackTrace();
    } finally {
      if ( in != null ) {
         in.close();
      if ( out != null ) {
         out.close();
      // add other conditions to close other closeable objects
    }The reasoning is that if an exception were ever to happen you would be sure that the clean up would be done. In your current example you may risk having an inputstream left open. Also note that BufferedReader.readLine() returns null when its arrived at the end of its content.

  • How I break while loop activity in BPEL process

    Hi Guys,
    I want to do a polling action in my bpel process, I put in the polling code in while activity ,
    I try two way to do the break :
    1. use the Flow activity , one sequence for while loop activity , one sequence for timeout flow , put waiting activity in it ,config timeout ... but Flow activity complete only when all branch complete . so it seems there is no way to break Flow from one branch.
    2.use onalarm branch of scope ... put while activity code in a scope activity , create onalarm branch for this scope ,config the timeout time ... but onalarm branch can't bypass the scope sequence...
    Any advice ?
    Thanks
    Kevin
    Edited by: kyi on Oct 29, 2009 1:01 PM

    The on-alarm branch of the scope should work.
    Maybe not so neat but you could try to do a scope with a flow within that. Put in one of the flow-branches a wait. After the wait throw an exception.
    You can catch that exception in a catch branch of the surrounding scope.
    Regards,
    Martien

  • Break out of a while loop from outside the loop

    Hello,
    I have an application where I have some nested while loops. Is it possible to break the innermost loop from a control that is outside of the inner loop? My inner loop is running a scan and read operation on the serial port and is reading data as it somes in. I need this loop to break when the user presses a button located in one of the outer loops so that another section of the vi can execute. Thanks in advance.
    Greg
    Gregory Osenbach, CLA
    Fluke

    Greg,
    You should place the terminal of the button in the innermost loop and wire out from there to the other locations the value is needed. If these are nested loops, the controls will not get read until the outer loop iterates again and this can only happen if the inner loop has ended anyway. Thus your scheme will not work.
    Alternatively, you can place the control in a loop that executes in parallel,then use local variables of it in the other locations, but the above solution is better.
    LabVIEW Champion . Do more with less code and in less time .

  • Sir i am using datasocket read ,i am communicating with java but my problem is that bcz im using while loop to see if value has changed my labview consumes all the processors time ,sir i want a event like thing so that while loop is not in continuous loop

    sir i have given lot of effort but i am not able to solve my problem either with notifiers or with occurence fn,probably i do not know how to use these synchronisation tools.

    sir i am using datasocket read ,i am communicating with java but my problem is that bcz im using while loop to see if value has changed my labview consumes all the processors time ,sir i want a event like thing so that while loop is not in continuous loopHi Sam,
    I want to pass along a couple of tips that will get you more and better response on this list.
    1) There is an un-written rule that says more "stars" is better than just one star. Giving a one star rating will probably eliminate that responder from individuals that are willing to anser your question.
    2) If someone gives you an answer that meets your needs, reply to that answer and say that it worked.
    3) If someone suggests that you look at an example, DO IT! LV comes with a wonderful set of examples that demonstate almost all of the core functionality of LV. Familiarity with all of the LV examples will get you through about 80% of the Certified LabVIEW Developer exam.
    4) If you have a question first search the examples for something tha
    t may help you. If you can not find an example that is exactly what you want, find one that is close and post a question along the lines of "I want to do something similar to example X, how can I modify it to do Y".
    5) Some of the greatest LabVIEW minds offer there services and advice for free on this exchange. If you treat them good, they can get you through almost every challenge that can be encountered in LV.
    6) If English is not your native language, post your question in the language you favor. There is probably someone around that can help. "We're big, we're bad, we're international!"
    Trying to help,
    Welcome to the forum!
    Ben
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • How can I update cluster items from inside a while loop that does not contain the cluster?

    I have a VI that contains front panel clusters and two while loops. The main cluster contains items such as a doubles "distance" and "stepsize" and boolean "step" (a whole buch of this type stuff). The first loop contains an event structure to detect front panel changes and the second contains code and sub VIs to perform operations based on detected events.
    The operator can enter data into either double or click the boolean. If distance is changed the second loop does what is required to process the change. The same happens with stepsize. If step is clicked the ±stepsize value is added to distance and the result is processed. In each case the front panel should track the result of the input and subsequent processing.
    Because the clusters are outside the while loop, they are not updated unless I click 'highlight execution' which seems to allow updating each time the execution highlight is updated. There are other issues if I move the clusters into one of the loops.
    I've tried referencing the clusters and using local variables and nothing works. It looks like overkill to use shared variables for this.
    Any ideas would be greatly appreciated.
    Thanks,
    Frank    

    Hi Ben,
    Thank you for the response. I followed the link and tried reading everything you posted on AEs but I'm afraid that I didn't understand it all. It seems that each AE example had a single input and a single output (e.g. a double). Is this the case? 
    What I have is a couple of front panel clusters containing (approximately) 18 control doubles, 8 indicator doubles, 5 boolean radio button constructs and 26 boolean control discretes. I clusterized it to make it readable. In addition I'll eventually have a cluster of task references for hardware handles.
    All I want to do is update the front panel values like I would do in a C, VB or any other language. I've tried referencing the cluster and using the reference from inside the loops. I've tied using local variables. Neither works. I'm experimenting with globals but it seems that I have to construct the front panel in the gloabal and then I wouldn't know how to repoduce that on the front panel of the main VI.  Sometimes it seems that more time is spent getting around Labview constructs than benefitting from them.
    I hope the 'Add Attachment' function actuals puts a copy of the VI here and not a link to it.
    Thanks again for the suggestion,
    Frank 
    Attachments:
    Front Panel Reference.vi ‏33 KB

  • Loop while is not visible

    Hi All,
    In SWDD (Every step type that can be inserted  )are visible but loop while is not visible.What could be the possible reason?Please let me know.
    Kind Regards,
    Anshu Kumar

    Hi Anshu,
    Would like to correct you that the step name is Loop (Until).
    Please check with the basis team if this step is not visible for you.
    Also check if you are not missing out this step while searching.
    Hope this helps!
    Regards,
    Saumya

Maybe you are looking for

  • Error with SSL Message

    Hello Guys, I am implementing solution where in I need to post http request to a secure server. I am using following mechanisam to talk to the ssl server. But when I run the program on my local machine I get following error. Can you guys please help

  • Adding item positions with reference to contract in sales order

    Hi all, I would be very grateful if some of you could help on this: I have a requirement to add lines with reference to a contract while the user is creating or modificating it via VA01 or VA02. The logic flow will be as follows: if the user enters a

  • [Apps] Name Card Application developed using Adobe AIR and Adobe Flash Lite

    An University student currently undergoing his research project had developed this application in order to help him with his research project. Please kindly try the application and take the survey form provided at the bottom of this message. This app

  • Issues downloading oracle bi publisher 11.1.1.5.0

    Erroring out when downloading Disk 1 parts 1 and 2 for for Linux x86-64-bit: Disk 2 part 1 also has issues The same issue was present in edelivery and http://www.oracle.com/technetwork/middleware/bi-enterprise-edition/downloads/biee-111150-393613.htm

  • MacBook Pro (retina display) power issues

    why wouldn't my mac turn on when I open it, I have to keep pressing the power button for 5 min before it turns on? even though I only left it to sleep and when it finally turns on it restarts again...i just bought it 5 months back and its brand new..