Results 1 to 9 of 9
Like Tree2Likes
  • 1 Post By KevinWorkman
  • 1 Post By gimbal2

Thread: Help with for loops :)

  1. #1
    Oldemor is offline Member
    Join Date
    Sep 2013
    Posts
    2
    Rep Power
    0

    Question Help with for loops :)

    got my answer, deleted it
    Attached Thumbnails Attached Thumbnails Help with for loops :)-heihei.png  
    Last edited by Oldemor; 09-18-2013 at 08:17 PM.

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,939
    Rep Power
    8

    Default Re: Help with for loops :)

    That line consists of one character repeated a bunch of times. Hmm, do you know any way to repeat some work a bunch of times?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Oldemor is offline Member
    Join Date
    Sep 2013
    Posts
    2
    Rep Power
    0

    Default Re: Help with for loops :)

    Yes ofcourse you can use a for loop for the line, but that seems like a waste of time and less elegant than just writing "-------------------------------------------------------------"

    opinions?

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,939
    Rep Power
    8

    Default Re: Help with for loops :)

    What you're asking is really a matter of personal opinion. Do whatever makes the most sense to you.

    Crossposted: Help to solve this for loop more effectively :)
    gimbal2 likes this.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,900
    Rep Power
    5

    Default Re: Help with for loops :)

    Quote Originally Posted by KevinWorkman View Post
    Do whatever makes the most sense to you.
    People underestimate just how full of wisdom this advice is. Especially because of the attached prerequisite: the need to actually make sense of it first.
    KevinWorkman likes this.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  6. #6
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,939
    Rep Power
    8

    Default Re: Help with for loops :)

    Quote Originally Posted by gimbal2 View Post
    People underestimate just how full of wisdom this advice is. Especially because of the attached prerequisite: the need to actually make sense of it first.
    School is back in session so we're getting a lot of students with questions like "how do I improve this code", and it's confusing to them because the honest answer is "don't." As long as the code makes sense to you and works, move on and keep coding. Anything you write at this point will make you cringe in 6 months anyway, so why bother wasting time on premature optimizations?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  7. #7
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,900
    Rep Power
    5

    Default Re: Help with for loops :)

    Yeah well, those are lessons only the worthy really learn, some quicker than others :) When starting out it is not too bad to want to improve on yourself as a learning exercise, as long as you take the time to actually reason and learn what is actually an improvement. The assumption quickly goes towards less code = faster code, but that was only really true before compilers started to become good at optimizing.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  8. #8
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,525
    Rep Power
    5

    Default Re: Help with for loops :)

    Please don't delete your threads or modify context which makes subsequent responses useless. How are others supposed to benefit from this? I noticed you deleted your thread on the other site as well.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  9. #9
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,197
    Rep Power
    19

    Default Re: Help with for loops :)

    Here's what was deleted in the last edit.

    db


    Hey! Im going to make a program that prints out this output into the consoll:
    Help with for loops :)-heihei.png

    my code prints out exactly that, and looks like this:

    Java Code:
     public static void main(String[] args) {
    
     int tabellSlutt = 9;
    
    
     for(int headerTeller = 0; headerTeller <= 9; headerTeller++) {
     System.out.print("\t" + headerTeller);
     }
    
     System.out.println("\n --------------------------------------------------------------------------------");
    
    
     for (int tabellStartBort = 0; tabellStartBort <= tabellSlutt; tabellStartBort++) {
    
     System.out.print(tabellStartBort + " | \t");
    
     for (int tabellStartNed = 0; tabellStartNed <= tabellSlutt; tabellStartNed++) {
     System.out.print((tabellStartBort * tabellStartNed) + "\t");
     }
     System.out.println();
     }
     }
    My question is, anyone knows a more effective/better organized way to set up this code (maybe a more elegant way to print out the line between the top numbers and the table)?Im only allowed to use for loops and print statements :) :)
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. for-to and do-x loops
    By AndrewM16921 in forum Forum Lobby
    Replies: 0
    Last Post: 12-13-2012, 09:32 AM
  2. Help with while loops
    By enjoy2225 in forum New To Java
    Replies: 9
    Last Post: 10-26-2012, 12:27 AM
  3. Need help with while loops
    By tangel in forum New To Java
    Replies: 0
    Last Post: 10-04-2011, 04:37 AM
  4. Replies: 20
    Last Post: 03-22-2011, 04:02 AM
  5. Help with loops
    By pg5678pg in forum New To Java
    Replies: 8
    Last Post: 10-17-2010, 06:51 PM

Posting Permissions

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