Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7657375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:01:00+00:00 2026-05-31T13:01:00+00:00

I was poking around some HTML5 Javascript demos and came across something I’ve never

  • 0

I was poking around some HTML5 Javascript demos and came across something I’ve never seen before in the syntax. Take a look at the run function and notice how the search object notation is made in the while loop. Lines of interest include 15 and 18. Can anyone explain this syntax?

function run() {
  var n = 1;
  search: while (running) {
    n += 1;
    for (var i = 2; i <= Math.sqrt(n); i += 1)
      if (n % i == 0)
       continue search;
    // found a prime!
    postMessage(n);
  }
}

(code taken from here; http://html5demos.com/js/cruncher.js)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T13:01:01+00:00Added an answer on May 31, 2026 at 1:01 pm

    This is not object (literal) notation, it is defining a label.

    A label can be used to give a looping construct a name. The benefits of doing this is that you can create more powerful breaks; or continues; by referencing outer loops (by their labels).

    Note that how the structure of the program you referenced is a:

    search: while () {
       for (;;;) {
    
       }
    }
    

    … and the author is using continue search; inside the for loop to continue the execution of the while loop.

    As for what’s happening on line 18, if (n % i == 0) is using the modulo (%) operator to get the remainder between dividing n / i, and checking whether it’s 0.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to javascript/jquery and I've done some poking around the web, but I
So I was poking around GMail the other day and ran across some interesting
I was just poking around into some new stuff in C++0x, when I hit
A while ago I was poking around with SQLite, trying to port some of
I'm poking around a bit in some of the more suspicious objects apple APIs
Whilst poking around some code using a .NET Reflector for an app I don't
I was curious about some serialization stuff so I went poking around FormatterServices and
I've been poking around in some projects written by one of our contractors, and
Alright, so I've been doing some poking around, and I realize my problem, but
(C#, prime generator) Heres some code a friend and I were poking around on:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.