none
get code

    Question

  • int[,] a = new int[10, 10];
                int x = 0;
                for (int i = 0; i <= a.GetUpperBound(0); ++i)
                {

                // Write software code within the brackets repetitive sentence
               // Fill the matrix above the values ​​of the total dimensional
               // You can not use any of the following sentences (For, foreach, while, do, goto)
                // You can use what you need from the conditional sentence If

                }

                string st = "";
                for (int i = 0; i < 10; ++i)
                {
                    for (int j = 0; j < 10; ++j)
                    {
                        st += a[i, j].ToString () + " ";
                    }
                    st += '\n';
                }
                MessageBox.Show(st);

    Thursday, October 17, 2013 7:10 PM

Answers

  • Actually, you can't do it with an "if", unless you are allowed to use "goto".  You must use "while".

    Tim Roberts, VC++ MVP Providenza & Boekelheide, Inc.

    Tuesday, October 15, 2013 8:46 PM
  • Hi Toofe81

    Thanks for your posting.
    From your description, I think that you can try to use recursion, Detailed information are shown in the following:

    using System;
    public class Example
    {
        public static void recursion(int i, int j)
        {

            if (j >= 0)
            {
                a[i, j] = i + j;   // 
                recursion(i, --j);
            }     

        }
        public static int[,] a = new int[10, 10];
        public static  void Main()
        {       
            int x = 0, i = 0, j ;
            for (i = 0; i <= a.GetUpperBound(0); ++i)
            {
                 j = a.GetUpperBound(1);
                 recursion(i, j);          
            }
            string st = "";
            for (i = 0; i < 10; ++i)
            {
                for (j = 0; j < 3; ++j)
                {
                    st += a[i, j].ToString() + " ";
                }
                st += '\n';
            }
            Console.WriteLine(st);
            Console.ReadKey();
        }
    }

    Hope these help.

     


    Lilia Gong <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Friday, October 18, 2013 8:42 AM

All replies

  • Rewrite this sentence

    for (int i = 0; i <= 10; ++i)

    using     if


    Tuesday, October 15, 2013 12:32 PM
  • Can you restate your question? I don't know what you're asking.
    Tuesday, October 15, 2013 1:00 PM
  • Not sure what you mean. You want to rewrite a for loop using an if statement? They have totally distinct functionality. It could probably be done with GOTOs, but there should be a really good reason to use them. 

    The real question here is why do you even want to do this?

    Tuesday, October 15, 2013 1:05 PM
  • This looks like a typical homework or exam question in a programming 101 class. 
    Tuesday, October 15, 2013 1:49 PM
  • Tip:

    You can do it by using a while(true) and checking a value with an if. Something like:

    // INDEXER
    
    while(true) {
    // Increase indexer by one
    // check value with if
    // and if you got the value - break the loop
    }

     

    Noam B.



    Do not Forget to Vote as Answer/Helpful, please. It encourages us to help you...

    Tuesday, October 15, 2013 3:06 PM
  • Actually, you can't do it with an "if", unless you are allowed to use "goto".  You must use "while".

    Tim Roberts, VC++ MVP Providenza & Boekelheide, Inc.

    Tuesday, October 15, 2013 8:46 PM
  •   int i =0;
    loopstart:
      if(i<=10){
        // do something
        ++i;
        goto loopstart;
      }


    Muthukrishnan Ramasamy
    net4.rmkrishnan.net
    Use only what you need, Reduce global warming

    Tuesday, October 15, 2013 10:31 PM
  • Rewrite this sentence

    for (int i = 0; i <= 10; ++i)

    using     if


    It equals to:

    int i=0;

    while(i<=10)
    {
        ++i;
    }


    Click For donating:Free Rice For the poor
    For spamming-sender issues, you can either report it at Microsoft Spamming Issue, or just find "Report Spam Here+Number" at Forum Issue;You can also find "Verify Your Account+Number" at "Forum Issue", where you can submit to be confirmed to paste links or images.
    For more things to talk about? StackOverFlow is your choice.

    Wednesday, October 16, 2013 2:08 AM
  • Dear toofe81,

    Is this question your homework:)? Welcome to MSDN, hope you can enjoy your time here

    int i = 0;
    if ( i++ < 10 )
    


    Wednesday, October 16, 2013 2:22 AM
  • thank you for all

    This duty and searched all the possible ways I did not find an answer

    int[,] a = new int[10, 10];
                int x = 0;
                for (int i = 0; i <= a.GetUpperBound(0); ++i)
                {
     // Write software code within the brackets repetitive sentence
     // Fill the matrix above the values ​​of the total dimensional
     // You can not use any of the following sentences  (For, foreach, while, do, goto)
     // You can use what you need from the conditional sentence If
             
                }
                string st = "";
                for (int i = 0; i < 10; ++i)
                {
                    for (int j = 0; j < 10; ++j)
                    {
                        st += a[i, j].ToString () + " ";
                    }
                    st += '\n';
                }
                MessageBox.Show(st);

    Wednesday, October 16, 2013 11:03 AM
  • Hi toofe81,

    This is a strange requirement which makes a simple question complex. Maybe you could define "a" as a jagged array to achieve your purpose. 

    int[][] a = new int[10][];
                int x = 0;
                for (int i = 0; i <= a.GetUpperBound(0); ++i)
                {
                    // Write software code within the brackets repetitive sentence
                    // Fill the matrix above the values ​​of the total dimensional
                    // You can not use any of the following sentences  (For, foreach, while, do, goto)
                    // You can use what you need from the conditional sentence If
                    if (x == 0)
                    {
                        a[i] = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
                    }
                    else
                    {
                        a[i] = new int[] { 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 };
                    }
                    
                }


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, October 16, 2013 12:05 PM
  • Matrix of two dimensions rather than one dimension

    Hi toofe81,

    This is a strange requirement which makes a simple question complex. Maybe you could define "a" as a jagged array to achieve your purpose. 

    int[][] a = new int[10][];
                int x = 0;
                for (int i = 0; i <= a.GetUpperBound(0); ++i)
                {
                    // Write software code within the brackets repetitive sentence
                    // Fill the matrix above the values ​​of the total dimensional
                    // You can not use any of the following sentences  (For, foreach, while, do, goto)
                    // You can use what you need from the conditional sentence If
                    if (x == 0)
                    {
                        a[i] = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
                    }
                    else
                    {
                        a[i] = new int[] { 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 };
                    }
                    
                }



    Wednesday, October 16, 2013 1:56 PM
  • You have not provided any sort of question.  What is your issue?
    Thursday, October 17, 2013 7:15 PM
  • Hi toofe81,

    What is your question? Please describe your problem in detail, and we will be able to provide quicker and better responses.

    Thanks.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, October 18, 2013 7:01 AM
  • I need the code dictate the total matrix row and column with out the use of tools(For, foreach, while, do, goto )and the possibility to use if

    {

    }

    Friday, October 18, 2013 8:14 AM
  • Hi Toofe81

    Thanks for your posting.
    From your description, I think that you can try to use recursion, Detailed information are shown in the following:

    using System;
    public class Example
    {
        public static void recursion(int i, int j)
        {

            if (j >= 0)
            {
                a[i, j] = i + j;   // 
                recursion(i, --j);
            }     

        }
        public static int[,] a = new int[10, 10];
        public static  void Main()
        {       
            int x = 0, i = 0, j ;
            for (i = 0; i <= a.GetUpperBound(0); ++i)
            {
                 j = a.GetUpperBound(1);
                 recursion(i, j);          
            }
            string st = "";
            for (i = 0; i < 10; ++i)
            {
                for (j = 0; j < 3; ++j)
                {
                    st += a[i, j].ToString() + " ";
                }
                st += '\n';
            }
            Console.WriteLine(st);
            Console.ReadKey();
        }
    }

    Hope these help.

     


    Lilia Gong <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Friday, October 18, 2013 8:42 AM
  • I need the code dictate the total matrix row and column with out the use of tools(For, foreach, while, do, goto )and the possibility to use if

    {

    }

    The question and the code comments are written in terrible English. For example "values of the total dimensional" and "I need the code dictate" make absolutely no sense in the English language.

    Cap'n

    Friday, October 18, 2013 10:28 PM