Learn Java Tutorial for Beginners, Part 5: For Loops

///Learn Java Tutorial for Beginners, Part 5: For Loops

Learn Java Tutorial for Beginners, Part 5: For Loops

FavoriteLoadingAdd to favorites

Get complete courses at
* Click the icon in the lower-right-hand corner to maximise! *
Part 5 of the Java tutorial for complete beginners from Cave of Programming. This time I’ll show you how to use ‘for’ loops in Java, as well as looking briefly at format specifiers for strings.

source

Java468x60
By |2019-07-21T21:17:44+00:00July 21st, 2019|Java Video Tutorials|35 Comments

35 Comments

  1. Jo Habib July 21, 2019 at 9:17 pm - Reply

    <3 Thank You

  2. ワンジクジェームス M. July 21, 2019 at 9:17 pm - Reply

    hi!
    just have a question. I am a total beginner so forgive my ingorance.

    on this part of the loop, when I change the loop from:

    for(int i = 0; i< 5; i = i + 1) {

    System.out.println("The value of i is: " + i);

    to

    for(int i = 0; i< 5; i = i ++) {

    System.out.println("The value of i is: " + i);

    }

    }

    it becomes an infinite loop which I don't see it happening in your eclipse.

    how do you keep editing and changing the codes without getting the output get mixed up as it is happening in my
    eclipse?

  3. Spencer Phelps July 21, 2019 at 9:17 pm - Reply

    Can you please do a video on nested for loops?

  4. Sofia Vinas July 21, 2019 at 9:17 pm - Reply

    I'm having trouble differentiating the types of loops and what they each specifically do. Any help?

  5. WappnZ July 21, 2019 at 9:17 pm - Reply

    Man thank you im gonna support your channel i watched videos in my langiage i couldnt even understand the java in my language but i understood you only thank you man i know the meaning if i and zero now cuz of u very thanks if u make videos about games i will be thank

  6. Dismember812 July 21, 2019 at 9:17 pm - Reply

    disgusting sounds from the mouth

  7. Walnut OfTerror July 21, 2019 at 9:17 pm - Reply

    printf command doesnt work for me, it says: The method printf(String, Object[]) in the type PrintStream is not applicable for the arguments (String, int)

  8. Colm Broaders July 21, 2019 at 9:17 pm - Reply

    Thanks for the videos. They are excellent!

  9. inadaizz July 21, 2019 at 9:17 pm - Reply

    Eclipse vs Netbeans? Why

  10. inadaizz July 21, 2019 at 9:17 pm - Reply

    So I just came from a video with terrible audio feedback and the such. The classical background music, excellent quality mic, and favorable accent is a welcome change.

    Now lets make some loops!

  11. BlueFlame123123 MC July 21, 2019 at 9:17 pm - Reply

    I'm 9 and I entered a coding contest and I won, beating kids who were 14 +. Mostly thanks to you!

  12. Peace July 21, 2019 at 9:17 pm - Reply

    OK John! I think this is what i was trying to do and this is what i did. Thank you. Today is the first day i am programming.

    public class Application {
    public static void main(String[] args) {
    for (int i = 0; i < 1000; i++) {

    System.out.println("Running");
    System.out.printf("Number of time looping is: %dn", i);
    int loop = 0;

    while (true) {

    if (loop < 1000) {
    break;
    }

    System.out.println("Running");
    }
    }

    }
    }

  13. Peace July 21, 2019 at 9:17 pm - Reply

    Wonderful! So well explained. Do we have a short cut for printf() method also like we have for println()
    I mean we press syso and then CTRL+SPACE.

    Another question is if i want to print it for 1000 times and i want to say something "First time the loop ran, value of i is 0" and Second time the loop ran then the value of i is 1" and so on.

    I hope my question is clear. I understand i can say for(int i = 0; i < 1000; i++){
    System.out.println("The value of i is:" + i);
    I want it to print something like which makes it very clear that this is first loop, second loop, third loop and so on
    }

    How do i do that ? Will i have to create another counter? I want it to be very clear in the print statement. I can't type 1000 println methods. Thanks a lot.

  14. mohibullah jalalzai July 21, 2019 at 9:17 pm - Reply

    very nice and i love it very helpful tutorial thanks you so much sir.
    but i did not understand what the %d dose and why do we need to write so can you tell me sir what the reason is ?

  15. deltoid 77 July 21, 2019 at 9:17 pm - Reply

    it works but apparently that little argument thing there is outdated
    and all you actually need to put is %d
    instead of %d/n

  16. Guram Kankava July 21, 2019 at 9:17 pm - Reply

    Thank you very much.

  17. jiao yuhang July 21, 2019 at 9:17 pm - Reply

    little advice, you don't have to create a new class all the time at the beginning of video,😄 ,thanks a lot for this series, it is really helpful.

  18. Prasneel Kumar July 21, 2019 at 9:17 pm - Reply

    Thanks to your videos, Java is starting to make sense.

  19. sorrefly July 21, 2019 at 9:17 pm - Reply

    I was scared by java but thanks to you…i'm starting to see this language program in a different way. And i think i'm gonna love it! Thanks 🙂

  20. johan jigsved July 21, 2019 at 9:17 pm - Reply

    The dubbel plus "++" dosen't seem to work for me.

    public class Loooooooooops {
    public static void main(String[] args) {

    for(int i=0; i < 5 ; i = i + 1) {

    System.out.println("Hello");

    }
    }
    }

    That works but this dosen't. I just get infinate "Hello". What could be the matter?

    public class Loooooooooops {
    public static void main(String[] args) {

    for(int i=0; i < 5 ; i = i++) {

    System.out.println("Hello");

    }
    }
    }

  21. Nihal JP July 21, 2019 at 9:17 pm - Reply

    What's the big difference between for and while loops?

  22. johncy estibeiro July 21, 2019 at 9:17 pm - Reply

    On my system, the loop doesn't run if I change System.out.printf(); to System.out.println(); it only works for printf.
    Error: method Printstream.println(double) is not applicable(actual and formal argument lists differ in length)

  23. Chris Sam July 21, 2019 at 9:17 pm - Reply

    public class Tutorial {
    public static void main(String[] args) {

    for(int i=0 ;i < 5; i++) {
    System.out.println("Hello");
    }
    }
    }

    Can anyone tell whats wrong here?

  24. yarpen26 July 21, 2019 at 9:17 pm - Reply

    thanks a lot for this printf method, i've never heard of it. i don't think it'll be of much use to me, seeing how simple my amateur programs are (in other words, nothing the usual print/println won't handle by means of pluses and quotation marks), but i can definitely understand how valuable they'd be when faced with the need of repeteadly putting in the same value in different places. also, it's cool that you provide us with all the shortcuts, such as sysout+Crtl+Space, might come in handy every once in a while

  25. SHlTY GooglePlus July 21, 2019 at 9:17 pm - Reply

    Very nice explained, but i can`t make the printf working …

    error :
    The method printf(String, Object[]) in the type PrintStream is not applicable for the arguments (String, int)

  26. DanielPM July 21, 2019 at 9:17 pm - Reply

    Love your tutorials!

  27. Eurodollar tv July 21, 2019 at 9:17 pm - Reply

    you are the best thanks a lot

  28. Ferenc July 21, 2019 at 9:17 pm - Reply

    Szia John.

    Could you please help me with this?

    I have tried to run to following code, but it  wont display the numbers of the iteration:

    int g;
     
     System.out.println("Enter 'L' to stop");
     
     for(g = 0; (char)System.in.read() != 'L';g++){
     System.out.println(g);
     }

    I noticed that it is running until i stop it, but just wont display anything , except the first sysout statement.

    Thanks a lot, Wildchild

  29. Rajeev Kumar July 21, 2019 at 9:17 pm - Reply

    i know what the mistake have you done. you haven't created a string i mean to say is that you must have written
    system.out.println("teh value of i is : +i ");
    instead of
    system.out.println("the value of i is: " + i);

    that means you wrote +i inside the quotation marks

  30. jc2782 July 21, 2019 at 9:17 pm - Reply

    you don't get nearly as many views as you deserve . 🙂

  31. iCroissant July 21, 2019 at 9:17 pm - Reply

    hee hee hee. look what I got:
    teh value of i is: + i
    teh value of i is: + i
    teh value of i is: + i
    teh value of i is: + i
    teh value of i is: + i

  32. Borat Sagdiyev July 21, 2019 at 9:17 pm - Reply

    Yes, but %d is much quicker.

  33. Chitra Indalkar July 21, 2019 at 9:17 pm - Reply

    printf stuff us nicely explained. loved way you simplifies things

  34. Tim Alm July 21, 2019 at 9:17 pm - Reply

    You don't have to put %d which is carryover from C as is printf. I just did the following: System.out.printf("The value of i is:" + i + "n");

  35. PCGamesundNews July 21, 2019 at 9:17 pm - Reply

    Subbed you

Leave A Comment

*