PDA

View Full Version : Java - for-loop?


zk0
12-15-2006, 02:04 PM
If I want to call this 500 times how do I do? With a for-loop?

public void timeTick()
{
++minutes;
if (minutes == 60)
{
minutes = 0;
++hours;
if (hours == 24)
{
hours = 0;
}
}
checkAlarm();
}

Spookster
12-15-2006, 02:37 PM
If you want to execute a piece of code an exact number of times then yes a for loop would be ideal to use.

Aradon
12-15-2006, 03:40 PM
To give a more specific answer without giving the answer, here is example code of adding ten times


public class test
{

public static void main(String args[])
{
int result = 0;
for(int i = 0; i < 10; i++)
{
result++;
}
}
}