switch

This is a discussion on switch within the C++ Programming forums, part of the General Programming Boards category; 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 ...

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

    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
    language hopper dennis.cpp's Avatar
    Join Date
    Jan 2011
    Location
    Herborn, Hesse, Germany
    Posts
    197
    You can't think of a way to verify it empirically? What about... trying it? Or did I get your question just wrong?
    Hardware: Intel® Core™ i7-3630QM CPU @ 2.40GHz × 8
    Operating system: Fedora 19 (64-Bit) / Linux 3.11.6-200.fc19 / KDE SC 4.11.2
    Compiler: gcc 4.8.2 with Netbeans IDE 7.4

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

  4. #4
    3735928559
    Join Date
    Mar 2008
    Location
    RTP
    Posts
    839
    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をこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,538
    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
    839
    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, 11:18 AM
  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

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