Thread: how to do cases with for,while,if command

  1. #1
    Banned
    Join Date
    Oct 2008
    Posts
    1,535

    how to do cases with for,while,if command

    i build functions and call them (only main)

    i need to write a program which does several things
    if you choose 1 ->go to one peace of code.
    of you choose 2 ->go to other

    when the operation of the code finishes
    the menu shows all over again

    how to do that without case ,switch
    Last edited by transgalactic2; 12-05-2008 at 09:58 AM.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Since you use the word "if", I would suggest using "if".

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    There are several ways, but the simplest is using "if" - however, it is typically what you SHOULD use switch for. for/while are much more awkward for the purpose of checking if a value is something in particular.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #4
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    thanks

  5. #5
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Example:
    Code:
    /* Here is a custom loop */
    
    loopy:
      if(x < 50)
      {
         /* Stuff goes here */
    
         x = x + 1;
         goto loopy;
      }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 26
    Last Post: 07-05-2010, 10:43 AM
  2. problem with "touch" command in c program
    By Moony in forum C Programming
    Replies: 10
    Last Post: 08-01-2006, 09:56 AM
  3. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 03:30 PM
  4. Ping problem
    By bladerunner627 in forum C++ Programming
    Replies: 12
    Last Post: 02-02-2005, 12:54 PM
  5. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM