Nested For loops

This is a discussion on Nested For loops within the C++ Programming forums, part of the General Programming Boards category; Okay, so I am a novice programmer, and I'm encountering my first inexplicable issue. I have a pair of nested ...

  1. #1
    Registered User
    Join Date
    Feb 2012
    Location
    Gunnison, Colorado, United States
    Posts
    10

    Nested For loops

    Okay, so I am a novice programmer, and I'm encountering my first inexplicable issue. I have a pair of nested for loops, meant to check for prime numbers. It is as follows.
    Code:
    #include <iostream>
    using namespace std;
    
    
    int main ()
    {
        int test;
        for (short int f=0; f <= 100; f++)
        {
            for (short int y=0; y <=100; y++)
            {
                test = f%y;
                if (test != 0)
                continue;
                else
                cout<< test;
            }
        }
    }
    It compiles fine, then crashes when I try to run it. I'm beyond this level, so I'm just frustrated as hell that some tweak is giving me all this trouble.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,548
    % by 0 has the same problem as / 0
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Feb 2012
    Location
    Gunnison, Colorado, United States
    Posts
    10
    Quote Originally Posted by Salem View Post
    % by 0 has the same problem as / 0
    ... Well don't I feel sheepish

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Nested loops
    By zeondik in forum C# Programming
    Replies: 2
    Last Post: 10-26-2008, 06:58 AM
  2. help with nested loops
    By geo_c in forum C Programming
    Replies: 15
    Last Post: 07-11-2004, 01:35 PM
  3. nested for loops
    By akub3 in forum C Programming
    Replies: 2
    Last Post: 04-01-2004, 05:21 AM
  4. nested for loops/
    By o0o in forum C++ Programming
    Replies: 2
    Last Post: 12-28-2003, 09:19 AM
  5. nested loops
    By briand. in forum C Programming
    Replies: 6
    Last Post: 10-01-2002, 05:15 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21