Thread: switch

  1. #1
    3735928559
    Join Date
    Mar 2008
    Location
    RTP
    Posts
    838

    switch

    Code:
    void foo()
    {
    	unsigned int x,y;
    	unsigned int n= rand();
    	switch(n%4)
    	{
    		for(x=0;x<1000;++x)
    		{
    			for(y=0;y<1000;++y)
    			{
    				case 0:
    					//special instructions
    					break;
    				case 1:
    					//special instructions
    					break;
    				case 2:
    					//special instructions
    					break;
    				case 3:
    					//special instructions
    					break;
    			}
    		}
    	}
    }
    in the code above, are switch statement cases evaluated in the inner loop? i'm thinking vs should be smart enough the answer is 'no', but i can't think of a way to verify it empirically, so i pose the question here.

    thanks.

  2. #2
    spaghetticode
    Guest
    You can't think of a way to verify it empirically? What about... trying it? Or did I get your question just wrong?

  3. #3
    3735928559
    Join Date
    Mar 2008
    Location
    RTP
    Posts
    838
    it seems perhaps you may not have appreciated the nuance of my problem.

  4. #4
    3735928559
    Join Date
    Mar 2008
    Location
    RTP
    Posts
    838
    nevermind. it seems as though despite this being a useful way to write a switch, it skips the block before the first case.

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Why would you even do this? The loop won't be executed.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    3735928559
    Join Date
    Mar 2008
    Location
    RTP
    Posts
    838
    evidently, yes.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. if else switch ????? which one ?
    By atlas07 in forum C++ Programming
    Replies: 5
    Last Post: 05-07-2010, 05:01 AM
  2. Switch??
    By alyeska in forum C++ Programming
    Replies: 1
    Last Post: 03-13-2009, 03:17 AM
  3. A switch that doesn't switch
    By Death_Wraith in forum C++ Programming
    Replies: 5
    Last Post: 11-06-2004, 12:18 PM
  4. please help about switch
    By frankieso in forum C Programming
    Replies: 10
    Last Post: 10-20-2004, 03:00 PM
  5. switch()
    By Max in forum C Programming
    Replies: 23
    Last Post: 07-13-2002, 03:06 PM