Click here to Skip to main content
13,048,406 members (105,317 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Simple 256 x 3 array with data of type string containing reps of numerical
Trying to write to console converted value but filter only one of the inner loop's cycles. 
Why can't the use of "if(rs = 0)" do the filtering?
using namespace System;
using namespace System::IO;
using namespace System::Text;
/* array of 256 x 3 */
void PrintValues(Array^ myArr);
int main()
  array<String^, 2>^testArray = gcnew array<String^,2>(256,3);
  /* zero (as string) array ... */
  for (int aa=testArray->GetLowerBound(0);aa<=testArray->GetUpperBound(0);aa++)
    for (int ab=testArray->GetLowerBound(1);ab<=testArray->GetUpperBound(1);ab++)
 /* comment this next three lines to avoid the print out of the array content */
  Console::WriteLine(" ");
  Console::WriteLine(" ");
  /* add some string content to the zeroed table */
  /* output the tabular data in an admittedly odd fashion (wait ... there's a point here) */
  for (int aa=testArray->GetLowerBound(0);aa<=testArray->GetUpperBound(0);aa++)
    for (int ab=testArray->GetLowerBound(1);ab<=testArray->GetUpperBound(1);ab++)
      if (Convert::ToInt32(testArray[aa,0])>0)
      /* this will return three runs at that value located @ testArray[45,0] all of which are 141 */
        Console::WriteLine("using GetValue: {0}", testArray->GetValue(aa,0));
    /* Now, here's the "filter" I'd like to add to this for loop; the reason for this question -> seems like a no brainer in an "if-then-else sense". But no! */
    //for (int aa=testArray->GetLowerBound(0);aa<=testArray->GetUpperBound(0);aa++)
    //	for (int ab=testArray->GetLowerBound(1);ab<=testArray->GetUpperBound(1);ab++)
    //	{
    //    if (Convert::ToInt32(testArray[aa,0])>0)
    //    /* this will never return ...  */
    //      if(ab=0)
    //      {
    //       Console::WriteLine("using GetValue: {0}", testArray->GetValue(aa,0));
    //      }
    //  }
void PrintValues( Array^ myArr )
  System::Collections::IEnumerator^ myEnumerator = myArr->GetEnumerator();
  int i = 0;
  int cols = myArr->GetLength( myArr->Rank - 1 );
  while ( myEnumerator->MoveNext() )
    if ( i < cols )
      i = 1;
    Console::Write(  "\t{0}", myEnumerator->Current );
Posted 14-Mar-12 9:44am
Updated 14-Mar-12 10:44am
OriginalGriff 14-Mar-12 15:59pm
The code block markers are visible, rather than acting to format the code - I have reported it in Sugs&Bugs.
It's not something you have done wrong - it's a bug by the looks of things!
Nelek 14-Mar-12 16:30pm
Edition: Pre Tags added (it did work for me, choosing a language not the basic pre's) and changed tabulations a bit to avoid many instructions being "multilined"

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

RedDK wrote:

Randor 14-Mar-12 17:56pm
Beware of the darkside. Stopped they must be; on this all depends. Yoda conditions I recommend.
CPallini 14-Mar-12 18:51pm
There is no dark side [...], really. As a matter of fact it's all dark.
SAKryukov 14-Mar-12 19:35pm
So funny you guys are. And I like the text of the anchor: "Ahem..." -- just right thing to say. 5 for the answer.
CPallini 15-Mar-12 4:14am
Thank you. :-)
RedDK 14-Mar-12 20:42pm
Thanks C,

if(ab==0) it is ...
pwasser 15-Mar-12 6:39am
I usually put the constant first and let the compiler do it's job.

SAKryukov 15-Mar-12 21:45pm
! :-)
Unfortunately, the trick does not work with two variables -- the bug won't be detected...
Randor 15-Mar-12 21:56pm
Left operand must be l-value.
SAKryukov 15-Mar-12 22:44pm
Yes, yes, I understand how your technique works. Of course. I just say, if the two are variables, and '=' is written by mistake instead of "==", this technique won't help, exactly because you introduce l-value anyway, and the bug get passes, agree?
Randor 15-Mar-12 23:06pm
Yes, if both variables are l-value then there is no trick for avoiding an erroneous assignment.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 14 Mar 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100