Thread: Random Walks/switch breakout

  1. #1
    Registered User
    Join Date
    Jun 2012
    Posts
    39

    Random Walks/switch breakout

    I am writing a program that generates a Random Walks pathway. In a part of the program I have a Switch statement nested in a While loop. If I use continue, it should bring me back to the beginning of the while loop right? I feel like it should, but if I'm wrong its gonna take me a heck of a lot of time to pull out the bug, which is why I thought I'd ask. Please, serious responses which answer my question.

  2. #2
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    Consider this a "freebie". In the future, my serious response will be: Did you write a simple program to test this behavior?
    Code:
    #include <stdio.h>
    
    
    int main(void)
    {
        int i;
    
    
        for (i = 0; i < 3; i++) {
            printf("i = %d\n", i);
            switch (i) {
                case 0:
                case 1:
                case 2:
                    continue;
                    break;
            }
            puts("If this prints, the continue statement didn't work");
        }
    
    
        return 0;
    }
    It won't be hard to pull out the bug if you don't code it straight into your big program.

    EDIT: Also, if adding a switch statement with a continue will make debugging that difficult, then I suspect one of two things. Either your code is not well organized/designed (perhaps a symptom of writing code before you fully understand the problem and have planned a solution on paper) or you are doing way too much coding between stopping to compile/test. Seriously, compile/debug/test every 10 or 20 lines of coding, or thereabouts, especially if you're fairly new to programming.
    Last edited by anduril462; 06-28-2012 at 05:30 PM.

  3. #3
    Registered User
    Join Date
    Jun 2012
    Posts
    39
    Fair enough. And thank you.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. switch and random num generator
    By got1sleeve in forum C++ Programming
    Replies: 17
    Last Post: 01-09-2008, 12:48 PM
  2. Breakout althorigm help!!!
    By hdragon in forum Game Programming
    Replies: 1
    Last Post: 02-21-2006, 12:03 AM
  3. My Breakout Clone is Insane
    By Grantyt3 in forum C++ Programming
    Replies: 10
    Last Post: 12-18-2005, 01:45 PM
  4. my breakout clone
    By lambs4 in forum Game Programming
    Replies: 12
    Last Post: 09-03-2003, 02:16 PM
  5. breakout collision
    By lambs4 in forum Game Programming
    Replies: 5
    Last Post: 03-13-2003, 03:23 PM