Understanding the game loop

So I’ve been using the game loop below for most of the games I’ve made and as I was just going through it I found there is one part I’m having trouble
trying to understand, specifically the line just below.



delta += (now - lastTime) / nanos; 


I understand we are finding the time difference and adding it to the delta variable but I don’t understand why we are then dividing it by the nanos variable (1000000000 / 60). I pasted the full game loop below.


 long lastTime = System.nanoTime(); 
			final double nanos = 1000000000.0 / 60.0; 
			double delta = 0;
			int frames = 0;
			int updates = 0;
			requestFocus();
			while(running){
				
				long now = System.nanoTime(); 
				delta += (now - lastTime) / nanos; 
				lastTime = now; 

				 while(delta >= 1){
					gameUpdate();
					delta--;
			
				}
					render(); 
				
	   }
	}
    } 


If anyone could help me by explaining whats happening on the line I pointed out, it would be very appreciated. Thanks!

Edit: I’ll just point you here instead of trying to explain, it’s easier and more comprehensible:
http://www.koonsolo.com/news/dewitters-gameloop/

I understand how the loop works, It was just that one line I was confused by, I just don’t get why we divide by 1/60th of a second.

Yeah, and that explains it. it’s not as simple as one answer fits all. Delta is your target time between frames per second, so depending on what sort of loop you’re aiming for it means different things. in your case, it’s checking if it’s been enough nano seconds to update, by dividing the nanoseconds in a second by your desired fps, then checking if the time between loops divided by this time is equal to or greater than 1, if it is, it updates. changing this will change how frequently you update.


 long lastTime = System.nanoTime(); 
			final double nanos = 1000000000.0 / 60.0; // We want 60 updates per second
			double delta = 0;
			int frames = 0;
			int updates = 0;
			requestFocus();
			while(running){
				
				long now = System.nanoTime(); 
            // for every 1/60th of a second, we add 1 to delta.
				delta += (now - lastTime) / nanos; 
				lastTime = now; 

				 while(delta >= 1){ 
					gameUpdate();
					delta--;
			
				}
					render(); 
				
	   }
	}
    }