How linear gameplay functions?

hello. i’ve been thinking about linearity in gameplay for a pretty long time now, more specifically the technical side of it.

maybe i am overthinking it too much, but i wanted to know your thoughts on how linear gameplay would function technically.

video games just run some code, yet some linear games are so long that you’d think the code would be very long too (maybe it is idk).

the way i see things, linear gameplay would probably go like:

  1. do a bunch of tasks
  2. end of level / chapter.
  3. load a new level / chapter
  4. repeat until player has reached the end of the game.

the thing that puzzles me is how linear games work on the technical side. is it just thousands of lines of code, or is it just a simple loop that keeps running over and over again until a condition has been met?