# "built-in loop" question

This topic is 1551 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Edit: Questions done, thanks for the answers.

-----

Hey guys, I'm planning on some day making a video series on Youtube, where I talk about certain game programming things. Without revealing too much, I'd like to ask you guys a couple of questions now and then, in order to be as accurate with the given topic as possible. I'm self-taught, so there might be some conventional details that I've overlooked.

So here's my first couple of questions:

1. What do you call the default process that automatically loops through the code and updates, whenever the program is ran? You know, the one where the computer tries to look for the Main function and run that, over and over again? Does it have an actual name, or is it fine to just call it a "built-in loop"?

2. Do all programming languages have a main function/method that the computer will look for and try to run? (I'm thinking it's a necessity, but please correct me if wrong)

3. Do all programming languages (today) cause the computer to loop infinitely through the code by default, unless you control it to do otherwise?

Edited by Malabyte

##### Share on other sites

1. What do you call the default process that automatically loops through the code and updates, whenever the program is ran? You know, the one where the computer tries to look for the Main function and run that, over and over again? Does it have an actual name, or is it fine to just call it a "built-in loop"?

There is no "built-in loop". The Main function/method is run precisely once. If you're thinking of the "Main Game Loop", then that has to be inserted by the programmer.

2. Do all programming languages have a main function/method that the computer will look for and try to run? (I'm thinking it's a necessity, but please correct me if wrong)

No, not all programming languages require a main function/method. Interpreted languages commonly don't require a Main. e.g. JavaScript, Scheme, Lua

3. Do all programming languages (today) cause the computer to loop infinitely through the code by default, unless you control it to do otherwise?

It's the other way around. Main is run exactly once. An infinite loop would have to programmed (or caused by a bug).

Edited by shacktar

##### Share on other sites
Um, in most languages main is run exactly once. There's no built-in loop.

In native languages main is called fist by virtue of how the compiler structures the executable. In interpreted languages, main is called by the language virtual machine.

##### Share on other sites

1. What do you call the default process that automatically loops through the code and updates, whenever the program is ran? You know, the one where the computer tries to look for the Main function and run that, over and over again? Does it have an actual name, or is it fine to just call it a "built-in loop"?

There is no "built-in loop". The Main function/method is run precisely once. If you're thinking of the "Main Game Loop", then that has to be inserted by the programmer.

Ah ok, thanks. I guess it's specific for Java then, as you have to manually terminate the program (e.g. in the IDE console) or declare EXIT_ON_CLOSE for a windowed app.

Edited by Malabyte

##### Share on other sites

Ah ok, thanks. I guess it's specific for Java then, because you have to manually close the process or else the program just keeps running.

Java just runs its main once, too. If your program keeps running, you're doing something to make that happen.

##### Share on other sites

Java just runs its main once, too. If your program keeps running, you're doing something to make that happen.

I'm talking about how the computer reads through the code in the class file. It "scans" through the first line, then the nth line until it reaches the bottom, then goes back to the first line again and reads all lines again. If it ran the code only once, then whenever you start to run the program it would immediately stop running, a millisecond or so afterwards.

For as long as I've been using Java, I've never had to explicitly tell the computer to continue to run the program. It will sometimes wait for some input or other change of its state, sure, but the program itself keeps "pulsing" through the class file(s). I've had to specifically tell it to terminate when I want it to. For instance, if you're using Eclipse to make a windowed Java application, then you specifically need to use the following line to terminate the program when you click the X to close the window (else the program keeps running even if the window isn't):

-----

window.setDefaultCloseOperation(EXIT_ON_CLOSE);

-----

I'm just very confused right now, I'm not sure what you guys are talking about. Does the Eclipse IDE, or the JFrame class specifically, have some sort of integral method that causes it the program to run continuously?

Edited by Malabyte

##### Share on other sites

Java just runs its main once, too. If your program keeps running, you're doing something to make that happen.

I'm talking about how the computer reads through the code in the class file. It "scans" through the first line, then the nth line until it reaches the bottom, then goes back to the first line again and reads all lines again. If it ran the code only once, then whenever you start to run the program it would immediately stop running, a millisecond or so afterwards.

For as long as I've been using Java, I've never had to explicitly tell the computer to continue to run the program. It will sometimes wait for some input or other change of its state, sure, but the program itself keeps "pulsing" through the class file(s). I've had to specifically tell it to terminate when I want it to. For instance, if you're using Eclipse to make a windowed Java application, then you specifically need to use the following line to terminate the program when you click the X to close the window (else the program keeps running even if the window isn't):

-----

window.setDefaultCloseOperation(EXIT_ON_CLOSE);

-----

I'm just very confused right now, I'm not sure what you guys are talking about. Does the Eclipse IDE, or the JFrame class specifically, have some sort of integral method that causes it the program to run continuously?

Java closes the application after all threads have finished executing (not when main is finished), main still only runs once though. (When you create a window the window system(Swing or AWT, other window systems may work differently) will have its own thread that keeps the application alive)

Edited by SimonForsman

##### Share on other sites

Java closes the application after all threads have finished executing (not when main is finished), main still only runs once though. (When you create a window the window system(Swing or AWT, other window systems may work differently) will have its own thread that keeps the application alive)

Ok, sweet. So I guess that, whenever you for instance make a console program with some println string, the string is rendered once and then kept updated by the console (e.g. Eclipse) or command prompt itself and not the program that initially rendered it? (unless, of course, you've explicitly told the program to wait for input or whatever).

If so, then everything makes perfect sense. Because then it's part of the IDE or the OS, I guess.

Edited by Malabyte

##### Share on other sites

Honestly, based on these questions and your 'understanding' shown in your replies, I don't think you should be trying to teach anyone anything - you clearly don't have the knowledge down at this point to be an authority source on the matter and any attempts to 'teach' others is going to do them more harm than good in the long run.

And you don't think that I will eventually acquire the knowledge, once I'm done with the research?

The bottom line is that there's an inconsistency in what I'm actually experiencing when I program, with the logic that has been explained to me in this thread. At least up until the point where SimonForsman elaborated on it.

Here's an example code:

class test {
public static void main (String[] args) {
System.out.println ("Hello world");
}
}

"Hello World" will show up in the console and it will keep showing up. No, it will obviously not visually repeat the line, for that you obviously need to create a loop of some sort. There's only a single line popping up. But that one line keeps itself visible on-screen and in Eclipse, the program doesn't terminate unless you specifically click on the terminate button. I'm just asking what causes that to happen, when I know that a screen ultimately consists of x*y pixels that keep updating as long as the PC screen is turned on. And if the program terminates, then what keeps updating the pixels on the screen? It sure ain't a terminated program.

You can be a pretty solid amateur programmer and still wonder about these subtle things, especially if you've been learning stuff through the internet (because there's all kinds of programming lingo and methodology that you have to figure out on your own). They are easy to miss, because they don't have much to do with the actual coding at all (assuming that we're talking about Java, which is the language I'm learning). There's a reason why a good University is sometimes superior to the internet.

So yes, I agree that I shouldn't be making videos until I know what I'm talking about. Which I'm not planning on doing, either. I just want to make a couple of videos (eventually) that I've yet to find on Youtube, because everyone's focused on teaching syntax and specific algorithms for specific tasks (but not teach people how to invent their own). But if someone else can beat me to it, then by all means. A Professional programmer with solid tutoring skills is a much better conveyor of information, anyways.

Edited by Malabyte

##### Share on other sites

So yes, I agree that I shouldn't be making videos until I know what I'm talking about. Which I'm not planning on doing, either.

Good but the key words in my reply were 'authority source' which means that realistically I would say you are still a good couple of YEARS away from being in any position to teach others with any real authority on matters.

##### Share on other sites

The program sends "Hello World" to the console, then exits. The console window (separate program) still keeps displaying what was sent to it.

##### Share on other sites

Good but the key words in my reply were 'authority source' which means that realistically I would say you are still a good couple of YEARS away from being in any position to teach others with any real authority on matters.

A valid opinion, but I honestly don't think people care, as long as the data is accurate and I have the ability to make myself understood. Science is not about trusting authority, it's about getting the facts straight. If anything, questioning authority is more akin to science. By your logic, Bucky Roberts @ thenewboston should've never started teaching his now 565 465 Youtube subscribers, because he wasn't much of an authority when he started out. He even dropped out of college. And Mark Zuckerberg invented Facebook, so authority hardly factors into it.

Granted, I agree that it helps to have a solid background, for credibility's sake and also if you want to be a general, cross-discipline teacher. A lot of people, if they see two possible sources, will obviously adhere better to the source with the greater authority. That's just human nature. We don't always have the time or resources to learn who or what is truly the more credibly source, so we take a calculated "risk" by trusting a known authority.

Edit: I guess I should also point out that I'm talking about a very basic tutorial that just helps people start making something on their own, without getting that writer's block. Nothing complex, albeit abstract and conceptual.

The program sends "Hello World" to the console, then exits. The console window (separate program) still keeps displaying what was sent to it.

I guess I understood Simon correctly then, thanks for the confirmation.

Edited by Malabyte

##### Share on other sites

Honestly, based on these questions and your 'understanding' shown in your replies, I don't think you should be trying to teach anyone anything - you clearly don't have the knowledge down at this point to be an authority source on the matter and any attempts to 'teach' others is going to do them more harm than good in the long run.

And you don't think that I will eventually acquire the knowledge, once I'm done with the research?

The bottom line is that there's an inconsistency in what I'm actually experiencing when I program, with the logic that has been explained to me in this thread. At least up until the point where SimonForsman elaborated on it.

Here's an example code:

class test {
public static void main (String[] args) {
System.out.println ("Hello world");
}
}

"Hello World" will show up in the console and it will keep showing up. No, it will obviously not visually repeat the line, for that you obviously need to create a loop of some sort. There's only a single line popping up. But that one line keeps itself visible on-screen and in Eclipse, the program doesn't terminate unless you specifically click on the terminate button. I'm just asking what causes that to happen, when I know that a screen ultimately consists of x*y pixels that keep updating as long as the PC screen is turned on. And if the program terminates, then what keeps updating the pixels on the screen? It sure ain't a terminated program.

You can be a pretty solid amateur programmer and still wonder about these subtle things, especially if you've been learning stuff through the internet (because there's all kinds of programming lingo and methodology that you have to figure out on your own). They are easy to miss, because they don't have much to do with the actual coding at all (assuming that we're talking about Java, which is the language I'm learning). There's a reason why a good University is sometimes superior to the internet.

So yes, I agree that I shouldn't be making videos until I know what I'm talking about. Which I'm not planning on doing, either. I just want to make a couple of videos (eventually) that I've yet to find on Youtube, because everyone's focused on teaching syntax and specific algorithms for specific tasks (but not teach people how to invent their own). But if someone else can beat me to it, then by all means. A Professional programmer with solid tutoring skills is a much better conveyor of information, anyways.

The console is not a part of the java application, it is a part of the OS and may or may not close after the program has finished running(depending on how it was launched, you can launch a standalone console by typing in cmd.exe in the run dialog in windows.

##### Share on other sites

Ok, I guess I got this part figured out. Thanks again, guys.

##### Share on other sites
I recommend getting a book instead of relying on internet tutorials. If you do then you'll realize why internet tutorials are woefully inadequate in learning your first language.

##### Share on other sites

A valid opinion, but I honestly don't think people care, as long as the data is accurate and I have the ability to make myself understood.

And there is lies the problem; until you are a well practised and know the subject inside out you don't know if it is accurate. But the people 'learning' from you also don't know if you are right or not, they just assume you are, so if you don't know the subject well then you are going to teach bad things and, frankly, the internet has enough bad information on it as it is and doesn't need more 'noobs' (to use the word from your signature) putting out more information they don't fully understand.

By your logic, Bucky Roberts @ thenewboston should've never started teaching his now 565 465 Youtube subscribers, because he wasn't much of an authority when he started out. He even dropped out of college. And Mark Zuckerberg invented Facebook, so authority hardly factors into it.

I'd never heard of that site before, so I went to check it out and had a look at his second C++ video explaining hello world and, honestly, based on getting 6mins into that video there is probably good cause for him not to have been trying to teach C++.... by 8mins in it was no better... by 9mins, oh god... I mean... oh god... '[main] should always have return 0', 'if you added text here [to cause an error] then it will never make it to [the return statement] so it will never return 0'... I mean, seriously... ugh.

And we aren't talking a small nit picking mistake there either; he fundamentally gets the C++ compilation model utterly wrong.. and not for the first time either... hell, don't get me started on 'all programs must have a main function' and 'your computer automatically knows to start at main' which is just wrong. (Yes, you can avoid the complications of how the OS and runtime do it but not by making statements of absolute truths like that!)

So, yeah, he probably shouldn't be teaching people C++ at least - and just because he has a large number of subscribers doesn't mean he is right, it just means he has a large number of subscribers.

And college has nothing to do with it; I wrote a series of articles for this site back in 2005 or 2006 for OpenGL and the only reason I did it is because I had a very strong background in the subject. At that point I hadn't completed university and didn't have a degree. Same goes for the chapter I wrote on the GLSL many years back.

Zuckerberg has nothing to do with it either; he made a website, he wasn't trying to teach people how to make a Facebook like website.

A lot of people, if they see two possible sources, will obviously adhere better to the source with the greater authority. That's just human nature. We don't always have the time or resources to learn who or what is truly the more credibly source, so we take a calculated risk.

Unfortunately that isn't the case; people see two sources they will take the one which looks easiest or quickest to learn from and go with that.
Given the choice between a correct book and a video which claims to be correct most people will, these days, more than likely take the video.

Of course if the internet wasn't full of incorrect tutorials we wouldn't have this problem but apparently its full of people who think "I've been coding for 20mins I must teach others so I can learn too!" which is just... ugh...

##### Share on other sites

And there is lies the problem; until you are a well practised and know the subject inside out you don't know if it is accurate. But the people 'learning' from you also don't know if you are right or not, they just assume you are, so if you don't know the subject well then you are going to teach bad things and, frankly, the internet has enough bad information on it as it is and doesn't need more 'noobs' (to use the word from your signature) putting out more information they don't fully understand.

Data is still data. If you actually know it, especially if it's been confirmed by a seasoned professional, then you know it. You don't need to be a seasoned professional yourself. What you're clearly talking about, has to do with larger (or entire) fields of science where expertise is synonymous to years worth of honing a multitude of different knowledges in order to grasp the full picture. And I can agree that some people indeed claim to know something that they don't.

But I'm talking about simple facts. No more and no less, so I'm just curious as to why you assume otherwise about me, since I haven't been saying anything about what I would specifically be talking about in my series. Learning programming is like learning anything else, you gradually learn more, the more you study. You don't study for X years and then suddenly you come to a point where all the information magically goes from 0-100% in a split second. Knowledge is modular and gradual.

In other words, basic scientific literacy. In this thread, I was asking about a very specific thing that's happening under the hood of the program and has nothing to do with the code you're actually writing (because it's happening at default, the program runs once unless you code it to do otherwise, as Simon and the others stated). So as a self-taught, then it's no wonder that I've missed it.

I'd never heard of that site before, so I went to check it out and had a look at his second C++ video explaining hello world and, honestly, based on getting 6mins into that video there is probably good cause for him not to have been trying to teach C++.... by 8mins in it was no better... by 9mins, oh god... I mean... oh god... '[main] should always have return 0', 'if you added text here [to cause an error] then it will never make it to [the return statement] so it will never return 0'... I mean, seriously... ugh.

Well, I'll admit that you've the advantage here of having watched that particular series. But in general, being a good teacher isn't just about telling people correct information. It's also about being sensitive to the student's mindset. The greatest teachers are able to engage their students and even create the illusion that the student have figured something out that the teachers did wrong. In actuality, the teacher did those mistakes on purpose. It's the same when your Drill Instructor screams in your face. Not because he's angry, frustrated or because he hates you, but rather the opposite. The clue is to motivate students and bolster their deeper learning of the subject in whatever way that is more relevant for the given subject. (Now, whether this is true for thenewboston, I can't really say, but it's possible (albeit hard to actually apply).)

Dr Robert Sapolsky, for instance, literally teaches his students outright false or outdated information before he makes a complete u-turn and throws it out the window. Almost like when a programmer does something silly in the first video and then refactors it in the next. This is possibly done in order for students to understand the sceptical nature of science, and it's also a solid history lesson that sticks with them.

As for Zuckerberg, I used him as an example to point out that authority can risk becoming a fixation with regards to how successful or accurate you are in your endeavours. Mark's not a teacher but, if he were, he would at least know what he's talking about. Even if he too ditched college.

Unfortunately that isn't the case; people see two sources they will take the one which looks easiest or quickest to learn from and go with that.

Given the choice between a correct book and a video which claims to be correct most people will, these days, more than likely take the video.

Of course if the internet wasn't full of incorrect tutorials we wouldn't have this problem but apparently its full of people who think "I've been coding for 20mins I must teach others so I can learn too!" which is just... ugh...

How quickly you can learn something is one thing, the credibility of the informatin is another. Both factor in, and there's even more factors involved here, but I won't digress further. I agree on the "...20 mins I must teach others..." syndrome though, it's almost a little creepy to witness at times. That's the Dunning-Kruger effect for you, right there (and it doesn't only happen on youtube or even the internet in general).

Edited by Malabyte

##### Share on other sites

Data is still data. If you actually know it, especially if it's been confirmed by a seasoned professional, then you know it. You don't need to be a seasoned professional yourself. What you're clearly talking about, has to do with larger (or entire) fields of science where expertise is synonymous to years worth of honing a multitude of different knowledges in order to grasp the full picture. And I can agree that some people indeed claim to know something that they don't.

But I'm talking about simple facts. No more and no less, so I'm just curious as to why you assume otherwise about me, since I haven't been saying anything about what I would specifically be talking about in my series. Learning programming is like learning anything else, you gradually learn more, the more you study. You don't study for X years and then suddenly you come to a point where all the information magically goes from 0-100% in a split second. Knowledge is modular and gradual.

In other words, basic scientific literacy. In this thread, I was asking about a very specific thing that's happening under the hood of the program and has nothing to do with the code you're actually writing (because it's happening at default, the program runs once unless you code it to do otherwise, as Simon and the others stated). So as a self-taught, then it's no wonder that I've missed it.

The point is that you don't know how what the data means or how to apply it. Data on it's own is meaningless. Context matters.

The fact that you still think it's something " that's happening under the hood of the program and has nothing to do with the code you're actually writing" shows you are still barely understanding the concept you're asking about and are certainly in no position to teach it.

Dr Robert Sapolsky, for instance, literally teaches his students outright false or outdated information before he makes a complete u-turn and throws it out the window. Almost like when a programmer does something silly in the first video and then refactors it in the next.

When you're starting out in any field, simple guidelines are a great help. But there is a world of difference between deliberately teaching a simplified (possibly even inaccurate) version of a complex problem and actually believing it oneself. You can only lie to your students if you a) realise it's a lie, b) understand why you're lying and c) know the truth yourself.

This is possibly done in order for students to understand the sceptical nature of science, and it's also a solid history lesson that sticks with them.

I doubt it. "Don't trust your teacher" is not a useful lesson to impart to beginners. For an intermediate student looking to advance, possibly...

I'm not trying to discourage you from programming, and I equally am not trying to belittle your programming knowledge. Everyone was there once and we all had some stupid assumptions. I looked over some of my earlier posts here the other day and cringed. The point is simply that you are really not ready to give anyone any kind of tutorial.

##### Share on other sites

The point is that you don't know how what the data means or how to apply it. Data on it's own is meaningless. Context matters.

Whether I know what the data means or how to apply it, depends on what data we're talking about and under which circumstance it is used. So yes, context matters.

Edited by Malabyte

##### Share on other sites

Those Buckys C++ tutorials seem to be liked (based on the youtube comments...). But man, that guy really has no business teaching that. It's clear from the videos that he has no deep understanding of what he's teaching, he has no idea what's going on under the hood, or the motivations for why certain things are the way they are in C++. He's really only imparting very superficial knowledge.

##### Share on other sites

I'm just asking what causes that to happen, when I know that a screen ultimately consists of x*y pixels that keep updating as long as the PC screen is turned on. And if the program terminates, then what keeps updating the pixels on the screen? It sure ain't a terminated program.

Not that it matters here but in actuality I wouldn't say that's true at all.

The monitor keeps the light on in its pixel crystals constantly, and updates their colors in frequent intervals of for example 60 times per second.

The monitor chooses the colors to update to from a signal that comes from the computer through the cable.

The signal is generated from the values of some memory in the graphics card.

If a color value is written to that memory it stays there until over-written or the power is turned off, so on the software side it's more that a pixel stays the same on the screen until it is actively changed in memory by a running program.

Then in actual actuality it's probably somewhat different again and depends on many things but I don't even know.

##### Share on other sites

The fact that you still think it's something " that's happening under the hood of the program and has nothing to do with the code you're actually writing" shows you are still barely understanding the concept you're asking about and are certainly in no position to teach it.

By that sentence, I was referring to what SimonForsman wrote, about the Main function running only once. Clearly, if that's what happens at default regardless of what code you write (unless you specifically tell it to run multiple times), then there you have it. It's "under the hood", albeit controllable by you as a programmer.

When you're starting out in any field, simple guidelines are a great help. But there is a world of difference between deliberately teaching a simplified (possibly even inaccurate) version of a complex problem and actually believing it oneself. You can only lie to your students if you a) realise it's a lie, b) understand why you're lying and c) know the truth yourself.

What makes you think that I'm planning on doing anything other than simple guidelines that are demonstrably true, regardless of who's teaching it? And what makes you think that I'm not going to also point out my own fallibility to the viewer and that everything I say can and will be used against me in a court of law?

I'm just wondering where you and phantom get those ideas from? Please, don't just assume a bunch of stuff about me just because I've happened to overlook how the computer reads a main class file on a technical level. That's purely incidental and I understood SimonForsman just fine, the way he explained it. If anything else, I'm a horrible forumer for dwelling on things excessively, but that can be easily explained by my insecurity, confusion and general bipolarity. Not to mention low social IQ.

I doubt it. "Don't trust your teacher" is not a useful lesson to impart to beginners. For an intermediate student looking to advance, possibly...

I'm not trying to discourage you from programming, and I equally am not trying to belittle your programming knowledge. Everyone was there once and we all had some stupid assumptions. I looked over some of my earlier posts here the other day and cringed. The point is simply that you are really not ready to give anyone any kind of tutorial.

I don't feel discouraged or belittled at all. I honestly prefer the "brutal honesty", but tutorials aren't just about giving deep, abstract advice. More often than not, a youtube tutorial series is mostly about giving people a heads up to what they're able to do. The "what" of something can be taught by anyone who knows it. What you're talking about is the "why" of something, which definitely demands a solid background of real experience.

##### Share on other sites
There is some strange stuff going on in this thread. For example, I don't think I can be on-topic in it because at this point, I don't know what the topic is.

But basically, I think Malabyte should listen to the community. If he releases Youtube videos without properly understanding, he could potentially get flamed by Youtubers, and build a bad reputation for himself. I wouldn't want to do that myself, or see it happen to others.

And then here I am, for some reason, trying to dig someone (Malabyte) out of a hole.

##### Share on other sites

Those Buckys C++ tutorials seem to be liked (based on the youtube comments...). But man, that guy really has no business teaching that. It's clear from the videos that he has no deep understanding of what he's teaching, he has no idea what's going on under the hood, or the motivations for why certain things are the way they are in C++. He's really only imparting very superficial knowledge.

I'm assuming that both you and phantom know your fair share of C++, so you both make an interesting point. But I also suspect that people will figure out that on their own, when they get confused by his said inconsistencies. Well, at least I did with regards to Java, and so I moved on to Java books, Oracle docs and TheCherno, once I got done with thenewboston. But I don't feel that thenewboston was a waste of time. But I'd imagine that he would be, if I checked him out after having already made my first Java game (my current project, together with a website).

I guess there's better teachers out there, after all. But if so, then maybe it's time for more pros to upload some videos on youtube. I think one of the reasons why a lot of youtubers are successful, also has to do with the lack of competition.

But basically, I think Malabyte should listen to the community. If he releases Youtube videos without properly understanding, he could potentially get flamed by Youtubers, and build a bad reputation for himself. I wouldn't want to do that myself, or see it happen to others.

Those are my concern as well, which is why I want to do it correctly. But I need to start somewhere, and doing research and learning about the stuff is the first step. Mike Rowe might not be an actual Dirty Jobber, but he sure knows how to present those jobs to people in an accurate way. But it's also kinda self-explanatory that nobody's ready until they're actually ready, so that's why I got a little confused. I guess people felt like they needed to tell me those things, because there's some people in this world who most definitely needs to be reminded. I don't mind.

Edited by Malabyte