Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

for loop will not loop

Tags:

java

for-loop

I have a for loop that I will use to compute time intervals to add to an ArrayList. The problem is that I can not prove that the for loop is being executed. Nothing is printed when using the system.out.println() statement, and nothing is added to the array from inside the loop ... any sugestions?

// lager tidspunkter og legger disse inn i en Array kalt tider
    tid.setTimer(16);
    tid.setMinutter(0);
    tid.setSekunder(0);
    tider.add(tid.asString());// String "16:00" is added as it should 
    System.out.println("tiden er: "+tid.asString());// gives 16:00 printed
    for(int i=0;i>12;i++){
        System.out.println("er i løkken");// gives nothing printed
        tid.increaseMinutter(30);
        System.out.println(tid.asString());// gives nothing printed
        tider.add(tid.asString());
    }
like image 664
Bjørn Jostein Aurheim Avatar asked Nov 27 '22 03:11

Bjørn Jostein Aurheim


2 Answers

You mean less than, not greater than:

for(int i=0;i<12;i++){ 
//           ^
like image 164
Mark Byers Avatar answered Dec 05 '22 17:12

Mark Byers


You condition is wrong: Change i>12 to i<12.

like image 44
Alon Adler Avatar answered Dec 05 '22 16:12

Alon Adler