Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. Undocumented problem with for each

Undocumented problem with for each

Scheduled Pinned Locked Moved Managed C++/CLI
data-structureshelplearning
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jmlsteele
    wrote on last edited by
    #1

    Code is self explanitory. Adding braces around the for each block fixes it, but this shouldn't be required. Unless of course you can point me to something that says this is expected behaviour. Jody Steele -----CODE START----- using namespace System; using namespace System::Collections; int main(array ^args) { //Define a test array ArrayList test; //Populate it with some data test.Add(3); test.Add(4); test.Add(13); test.Add(42); //Works as expected: WriteLine not called if (false) Console::WriteLine("Test"); //Works as expected: for not entered if (false) for(int i=0;i

    J N 2 Replies Last reply
    0
    • J jmlsteele

      Code is self explanitory. Adding braces around the for each block fixes it, but this shouldn't be required. Unless of course you can point me to something that says this is expected behaviour. Jody Steele -----CODE START----- using namespace System; using namespace System::Collections; int main(array ^args) { //Define a test array ArrayList test; //Populate it with some data test.Add(3); test.Add(4); test.Add(13); test.Add(42); //Works as expected: WriteLine not called if (false) Console::WriteLine("Test"); //Works as expected: for not entered if (false) for(int i=0;i

      J Offline
      J Offline
      jmlstele
      wrote on last edited by
      #2

      Just in case my message about what fixes it wasn't clear: Bad: ----CODE---- if (false) for each (int i in test) { Console::Write("for each "); Console::WriteLine(i); } ----CODE END---- Good: ----CODE---- if (false) { for each (int i in test) { Console::Write("for each "); Console::WriteLine(i); } } ----CODE END---- But yeah... Original question still stands: Is this a "feature" or a genuine bug?

      1 Reply Last reply
      0
      • J jmlsteele

        Code is self explanitory. Adding braces around the for each block fixes it, but this shouldn't be required. Unless of course you can point me to something that says this is expected behaviour. Jody Steele -----CODE START----- using namespace System; using namespace System::Collections; int main(array ^args) { //Define a test array ArrayList test; //Populate it with some data test.Add(3); test.Add(4); test.Add(13); test.Add(42); //Works as expected: WriteLine not called if (false) Console::WriteLine("Test"); //Works as expected: for not entered if (false) for(int i=0;i

        N Offline
        N Offline
        Nish Nishant
        wrote on last edited by
        #3

        Definitely looks like a bug to me. Regards, Nish


        Nish’s thoughts on MFC, C++/CLI and .NET (my blog)
        Currently working on C++/CLI in Action for Manning Publications.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups