Evaluation of nested loops

This is a discussion on Evaluation of nested loops within the C Programming forums, part of the General Programming Boards category; Hello, All Another semester is upon us. I will teach C Programming at my college again this semester (as well ...

  1. #1
    CS Author and Instructor
    Join Date
    Sep 2002
    Posts
    511

    Evaluation of nested loops

    Hello, All

    Another semester is upon us. I will teach C Programming at my college again this semester (as well as Java and C++)

    I am looking for tips and tricks to show my students how to evaluate nested loops like


    for (etc,,)
    for (etc)

    I like to show how the code actually does work by tracing throught the code. AS you know it can get confusing quickly.

    I thought somewhere here or on another board someone posted a good shortcut for evaluating nested loops.

    I have tried google. Not much there to help.

    Thanks for the ideas Mr. C
    Mr. C: Author and Instructor

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,164
    You mean you want something like:
    Code:
    int main(void)
    {
      int i, j;
    
      for(i = 0;i < 5;++i)
        for(j = 0;j < 5;++j)
          printf("%d %d\n", i, j);
    }
    ? I'm confused as to what you're looking for.
    If you understand what you're doing, you're not learning anything.

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,546
    Well iterating through all the elements of a 2D array (or a matrix) is one example
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Nested loops
    By zeondik in forum C# Programming
    Replies: 2
    Last Post: 10-26-2008, 06:58 AM
  2. nested for loops
    By akub3 in forum C Programming
    Replies: 2
    Last Post: 04-01-2004, 05:21 AM
  3. nested for loops and bank account interest help!!
    By webvigator2k in forum C++ Programming
    Replies: 1
    Last Post: 04-07-2003, 08:03 PM
  4. Output from nested loops
    By IzaakF in forum C Programming
    Replies: 2
    Last Post: 09-01-2002, 06:09 AM
  5. nested for loops
    By Unregistered in forum C Programming
    Replies: 4
    Last Post: 11-17-2001, 10:44 AM

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