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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Other Discussions
  3. IT & Infrastructure
  4. Any good Loop related training, quizes, problems, etc, links?

Any good Loop related training, quizes, problems, etc, links?

Scheduled Pinned Locked Moved IT & Infrastructure
questioncareeralgorithmsjsontutorial
7 Posts 2 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.
  • R Offline
    R Offline
    Red_Wizard_Shot_The_Food
    wrote on last edited by
    #1

    I'm after some good links of questions, quizes and problems relating to loops, flow control, sorting and good practice in such matters, just so I can buff up on them. I had a job interview last year and I aced all the questions on the exam in about 5 mins flat... and then I came to one question with a simple loop in it and after I compiled the code once and it didn't work I choked, got tunnel vision and practicly forgot how to code for the rest of the exam... I nailed it in the end, but having a time on all other questions that shoked the interviewer then having a 45 mins time on a horribly simple question just blew the whole thing for me. Admitedly the fault was 99% nerves and 1% my knowledge of flow control.. but I feel if I buff up on them then it will serve to boost my confidence for upcomming interviews after the freezing disaster of last year. Cheers :)

    P 1 Reply Last reply
    0
    • R Red_Wizard_Shot_The_Food

      I'm after some good links of questions, quizes and problems relating to loops, flow control, sorting and good practice in such matters, just so I can buff up on them. I had a job interview last year and I aced all the questions on the exam in about 5 mins flat... and then I came to one question with a simple loop in it and after I compiled the code once and it didn't work I choked, got tunnel vision and practicly forgot how to code for the rest of the exam... I nailed it in the end, but having a time on all other questions that shoked the interviewer then having a 45 mins time on a horribly simple question just blew the whole thing for me. Admitedly the fault was 99% nerves and 1% my knowledge of flow control.. but I feel if I buff up on them then it will serve to boost my confidence for upcomming interviews after the freezing disaster of last year. Cheers :)

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      The quick guide: If you have the control condition at the top of the loop, then the loop does not always need to execute. Example:

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

      This only executes the loop conditions if count is greater than 0. If the control condition is at the bottom of the loop, then it must execute at least once. Example:

      int i = 1;
      do
      {
        i++;
      }while(i < 1);
      

      This executes once. In this example, you wouldn't really want to use this loop because it executes even though the condition plainly states that it shouldn't. When you use them really depends on whether it has to execute at least once or not. I hope that helps.

      Deja View - the feeling that you've seen this post before.

      R 1 Reply Last reply
      0
      • P Pete OHanlon

        The quick guide: If you have the control condition at the top of the loop, then the loop does not always need to execute. Example:

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

        This only executes the loop conditions if count is greater than 0. If the control condition is at the bottom of the loop, then it must execute at least once. Example:

        int i = 1;
        do
        {
          i++;
        }while(i < 1);
        

        This executes once. In this example, you wouldn't really want to use this loop because it executes even though the condition plainly states that it shouldn't. When you use them really depends on whether it has to execute at least once or not. I hope that helps.

        Deja View - the feeling that you've seen this post before.

        R Offline
        R Offline
        Red_Wizard_Shot_The_Food
        wrote on last edited by
        #3

        Cheers mate, Thats a bit rudimentry for what am after ;) I was looking more for loop and flow control based conundrums; as I have faced a few tricky ones over a number of interviews (some even to the point that they are "trick" questions) and my ability to apply logic under interview conditions is always hampered by nerves... So I was hoping to cram a load of real traicky-SoB loop based problems before some up-comming interviews. I've got my do-while's, while-do's, if's, else if's, switch cases(even that evil "C# requires break's" quesiton they throw into confuse C/C++ coders), try-catch-finaly's down pat.. but I'm after some exposure-therapy on them so I can hold my logical-nerve when faced with loop/flow/sort based exam questions made the throw a spanner in the works.

        P 1 Reply Last reply
        0
        • R Red_Wizard_Shot_The_Food

          Cheers mate, Thats a bit rudimentry for what am after ;) I was looking more for loop and flow control based conundrums; as I have faced a few tricky ones over a number of interviews (some even to the point that they are "trick" questions) and my ability to apply logic under interview conditions is always hampered by nerves... So I was hoping to cram a load of real traicky-SoB loop based problems before some up-comming interviews. I've got my do-while's, while-do's, if's, else if's, switch cases(even that evil "C# requires break's" quesiton they throw into confuse C/C++ coders), try-catch-finaly's down pat.. but I'm after some exposure-therapy on them so I can hold my logical-nerve when faced with loop/flow/sort based exam questions made the throw a spanner in the works.

          P Offline
          P Offline
          Pete OHanlon
          wrote on last edited by
          #4

          Aahh, so they've included conditions like breaks where you have to match the break to the loop? That type of thing?

          private int y = 0;
          
          public void DoThis()
          {
            int x = 1;
            while (y < 10) {
              switch (x %2)
              {
                case 0:
                 Console.WriteLine("I'm even");
                 break;
                case 1:
                 Console.WriteLine("I'm odd");
                 break;
              }
              x = Evaluate(x);
              if ( y > 10)
              {
                Console.WriteLine("Y is {0}", y);
                break;
              }
            }
          }
          
          private int Evaluate(int y)
          {
            y = 11;
            y = EvaluateX(y);
            return y;
          }
          
          private int EvaluateX(int x)
          {
            y = (++x)*3;
            return x;
          }
          

          What will be written to the console?

          Deja View - the feeling that you've seen this post before.

          R 1 Reply Last reply
          0
          • P Pete OHanlon

            Aahh, so they've included conditions like breaks where you have to match the break to the loop? That type of thing?

            private int y = 0;
            
            public void DoThis()
            {
              int x = 1;
              while (y < 10) {
                switch (x %2)
                {
                  case 0:
                   Console.WriteLine("I'm even");
                   break;
                  case 1:
                   Console.WriteLine("I'm odd");
                   break;
                }
                x = Evaluate(x);
                if ( y > 10)
                {
                  Console.WriteLine("Y is {0}", y);
                  break;
                }
              }
            }
            
            private int Evaluate(int y)
            {
              y = 11;
              y = EvaluateX(y);
              return y;
            }
            
            private int EvaluateX(int x)
            {
              y = (++x)*3;
              return x;
            }
            

            What will be written to the console?

            Deja View - the feeling that you've seen this post before.

            R Offline
            R Offline
            Red_Wizard_Shot_The_Food
            wrote on last edited by
            #5

            Excelent :) really liked that one .. Even down to the EvaluateX and Evaluate being so closley named then calling Evaluate(x)to trick my hasty reading of it to cause me to think it was EvaluateX being called... Even worse.. the first time I read it I missed the second break and assumed it would loop through all of 0-10. That is exaclty the stuff I'm after :D "I'am odd" "Y is 36" ?? Cheers.

            P 2 Replies Last reply
            0
            • R Red_Wizard_Shot_The_Food

              Excelent :) really liked that one .. Even down to the EvaluateX and Evaluate being so closley named then calling Evaluate(x)to trick my hasty reading of it to cause me to think it was EvaluateX being called... Even worse.. the first time I read it I missed the second break and assumed it would loop through all of 0-10. That is exaclty the stuff I'm after :D "I'am odd" "Y is 36" ?? Cheers.

              P Offline
              P Offline
              Pete OHanlon
              wrote on last edited by
              #6

              Glad you liked it.

              Deja View - the feeling that you've seen this post before.

              1 Reply Last reply
              0
              • R Red_Wizard_Shot_The_Food

                Excelent :) really liked that one .. Even down to the EvaluateX and Evaluate being so closley named then calling Evaluate(x)to trick my hasty reading of it to cause me to think it was EvaluateX being called... Even worse.. the first time I read it I missed the second break and assumed it would loop through all of 0-10. That is exaclty the stuff I'm after :D "I'am odd" "Y is 36" ?? Cheers.

                P Offline
                P Offline
                Pete OHanlon
                wrote on last edited by
                #7

                BTW - did you catch the scope variable in ExecuteX? y is actually the instance level variable there. It's the little one's like this that tend to get people.

                Deja View - the feeling that you've seen this post before.

                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