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 8621625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:51:41+00:00 2026-06-12T06:51:41+00:00

Warning: Simple homework assignment, no idea what I’m doing So, I’m trying to make

  • 0

Warning: Simple homework assignment, no idea what I’m doing

So, I’m trying to make a program that finds the first prime numbers from 1 to 100 and prints them in a listbox. This is my code:

private bool IsPrime(int number)
{
    int count;
    if (number == 2)
        return true;
    for (count = 3; count < number; count = count + 2)
    {
        if (number % count == 0)
            return false;
    }
    return true;
}

private void calculateButton_Click(object sender, EventArgs e)
{
    int number;
    for (number = 1; number < 100; number = number++)
        if (IsPrime(number))
            primeList.Items.Add(number);
}

And the program isn’t catching any syntax errors, but it also freezes up every time I try to run it. Any idea why this happens? Thanks.

  • 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-06-12T06:51:42+00:00Added an answer on June 12, 2026 at 6:51 am

    You use:

    for (number = 1; number < 100; number = number++)
    

    while you should write

     for (number = 1; number < 100; number++)
    

    You should read these articles to understand why your original code didn’t increment the : for, ++ Operator

    You can learn the behaivour of the ++ operator in some test code:

            int n = 0;
            Console.WriteLine(n); //0
            n = n++;
            Console.WriteLine(n); //0
            n = ++n;
            Console.WriteLine(n); //1 
            n = n++;
            Console.WriteLine(n); //1
            n = ++n;
            Console.WriteLine(n); //2
    

    Another nice example would be:

            int n = 0;
            int x = n++;
            int y = ++n;
            Console.WriteLine(string.Format("x={0}", x)); //0
            Console.WriteLine(string.Format("y={0}", y)); //2
            Console.WriteLine(x + y); //n++ + ++n == 0 + 2 == 2
            n = 0;
            x = ++n;
            y = n++;
            Console.WriteLine(string.Format("x={0}", x)); //1
            Console.WriteLine(string.Format("y={0}", y)); //1
            Console.WriteLine(x + y); //++n + n++ == 1 + 1 == 2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to implement simple xhr abstraction, and am getting this warning when
I made a simple program that allows the user to pick a number of
Newbie Warning I have a simple but vexing problem trying to disable an NSButton.
In Django I have a package that issues a depreciation warning (django.views.generic.simple). It would
Probably a simple question: Why do I get an compiler warning for the following
While including the simple HTML DOM library, I get the warnings: Warning: file_get_contents() [function.file-get-contents]:
I have a bit of sample code that is throwing this warning: main.c: In
Warning: Note that this is a dumb question of something that I would probably
I have three questions regarding a homework assignment for C++. The goal was to
(WARNING: this is my first java application, coming from .NET, so don't bash me

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.