• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How programs work in web-based programming with loops?

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello world, I would like to know when it is necessary to write a do loop vs a while loop. Also if I am trying to write a massive javascript program, do you have to keep the programming running by a loop if its for website development? From playing around with it, it seems I use the onload = function name() to call my function and keep it looping based on events that happen when the user pressing something on the website. Any thoughts on this matter would be appreciated thanks in advances.
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jack,
A do loop is when you always want the loop to run at least once. With JavaScript, the event listener gets called each time. For example, onclick gets called each time you click so you don't have to poll for it.

Note that Java and JavaScript are different languages. For JavaScript questions, you'll want to post in the HTML/JavaScriptforum. For Java questions, here is good.

 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For web programming, the browser handles the event loop and invokes event handlers in your code on your behalf. You do not maintain any event loop in your own code.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jack Ryu wrote:it seems I use the onload = function name() to call my function and keep it looping based on events that happen when the user pressing something on the website.


No. You don't need to do anything to "keep it looping". The browser does that all on its own. The load event is just one example of an event that you can write a handler for. It is not necessary to have a load handler to "start" anything.
 
Every time you till, you lose 30% of your organic matter. But this tiny ad is durable:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic