Nesting “for” Loop n Times

前端 未结 1 1168
甜味超标
甜味超标 2021-01-19 19:35

I\'m writing a program that finds passwords. I ran into a problem when I saw that the \"for\" loops to replace parts of the password would have to be repeated for the variab

相关标签:
1条回答
  • 2021-01-19 20:00

    You do not need to repeat the for loop. Instead you need to nest it.
    The most inviting solution to implement this is a recursive construct.

    Pseudo code:

    void nestloop(int depth, int width)
    {
        if(depth>0)
        {
            int i;
            for (i=0; i<width; i++)
            {
                nestloop(depth-1, width);
            }
        } else
        {
            /* do whatever you need done inside the innermost loop */
        }
    }
    
    0 讨论(0)
提交回复
热议问题