Results 1 to 8 of 8

Thread: Joining loops?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1

    .

    The diamond didn't format.

    ---*---
    --***--
    -****-
    ******
    -****-
    --***--
    ---*---

    or soemthing..

    Out of curisoity though, what did you mean when you said you coudl "draw" the shape? Its out of the scope of the assignment but it'd still be great to know and how would you go about it without using loops?

  2. #2
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25
    Oh... you mean you're using ASCII in a console to print out different shapes. I was under the assumption that you were using actual graphics instead. Guess I should have actually looked at your code.

    In that case, yeah you could use a nested for loop to do what you propose. Nesting is just placing one inside of the other. For example...

    Code:
    var i, j: Integer;
    
    for i := 0 to 10 do
      for j := 0 to 10 do
        writeln('(' + inttostr(i) + ', ' + inttostr(j) + ')');
    ...would give you a print-out of all the combinations of values the i and j variables go though for the entire run of this program's nested for loops. Try it and see how it works.

    You can see that the inside loop completes before the outer one as it runs through it's iterations before the encasing for loop moves onto it's next iteration. So in plain language, each i value will go through all the j values as the for loop using i moves along.

    You can have multiple nesting of for and other types of loops, if conditionals and all of the other constructs that make up the Pascal language. You can even get really crazy with this too and code yourself into a messif you aren't keeping track of what you're doing logically. Just be sure that you know what each does and that it is in fact something that you need it to do. It takes practice and time to get to know what you need for each programming problem. Comes with experience so just try different things to see what works best for each case scenario. Often what is the right way and what is the wrong way to program something all depends on what the problem is and ultimately what the program is trying to accomplish.
    Jason McMillen
    Pascal Game Development
    Co-Founder





Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •