Nested For Loop In Java Tutorial #24

Поделиться
HTML-код
  • Опубликовано: 7 сен 2024
  • $1,000 OFF ANY Springboard Tech Bootcamps with my code ALEXLEE. See if you qualify for the JOB GUARANTEE! 👉 bit.ly/3HX970h
    The nested for loop in java is just a for loop inside of a for loop. A common way to use a nested for loop in java is to get elements from a 2d array. To do that, your outer for loops takes care of the rows and your inner for loop takes care of the columns.
    Java loops can be VERY tricky, but don't worry too much about it right now! Use the code I provided and after time you'll get the hang of java loops :) If you followed along, congrats! You learned-by-doing!
    I hope you enjoyed this nested for loop in java tutorial! I like to have a nice mix of tutorials and actual projects for you all :)
    🌅 Source Code - github.com/ale...
    Do you want to learn how to code from scratch, in Java? Check out my Java Tutorial For Beginners: • Coding For Beginners I...
    How are you using nested for loops in java? -
    Full Java Tutorial For Beginners Playlist: • Full Java Course by Al...
    Free Tips: bit.ly/3U6HXcb
    Disclosure: The Springboard link provided is linked to my affiliate account & supports the channel.
    ~
    Alex Lee

Комментарии • 227

  • @alexlorenlee
    @alexlorenlee  10 месяцев назад +2

    If you’re new to programming but want a career in tech, I HIGHLY RECOMMEND applying to one of Springboard’s online coding bootcamps (use code ALEXLEE for $1,000 off): bit.ly/3HX970h

  • @sprutxz
    @sprutxz 3 года назад +110

    I didn't pay attention in my java class and now this guy saved my life

  • @PeanutButter2024
    @PeanutButter2024 4 года назад +92

    This guy the GOAT, best tutorials I've seen

  • @aquarocket8165
    @aquarocket8165 4 года назад +23

    If you have an array with different dimmensions try:
    for(int i =0; i< array.lenght; i++) {
    for(int j =0; j< array[0].length; j++) {
    }
    }
    This will go through all values in array that is or isnt square

    • @mohammedibrahim8428
      @mohammedibrahim8428 2 года назад +1

      This is a great tip! Also just in case you have a different number of items in each row, you could improve upon this by checking the length of each row:
      for (int i = 0; i < array.length; i++)
      for (int j = 0; j < array[i].length; j++)
      System.out.println(array[i][j]);

  • @TheGallyp
    @TheGallyp 4 года назад +18

    Alex, people like me need your videos! Whenever I am confused about anything or need an explanation I can understand I can always count on you. Please never stop making videos!

  • @zxrif5004
    @zxrif5004 4 года назад +17

    I had no idea what we were doing in class today, thanks for the help!

  • @vishaalguru9666
    @vishaalguru9666 5 лет назад +9

    Myself in APCSA class, first time student come from India to US of A, my first teacher Sridhar Kandukari very smart man, he help me now u teach me, very nice sir, vineeth kandukuri also likes ur teachigg always watches video with fav lemon pickle recipe from vah chef

  • @dokadoki6514
    @dokadoki6514 3 года назад +20

    Ah im telling you im gonna fall in love with this guy HAHA
    What a life saver hahaahsha thanks man!

  • @heineken9329
    @heineken9329 4 года назад +34

    Thanks for explaining clearly, this nested is so hard for me at starting 2 months at coding. Nested and array are so difficult.

  • @phanta5m
    @phanta5m 3 года назад +1

    Good thing i ran to your videos while learning java , the old concept i learned in cpllege are now cleaner, good job Alex.

  • @rittenbrake1613
    @rittenbrake1613 4 года назад +2

    hey I think u teach better than others , esp in explaining the nested loops topic , listing all i and j

  • @nicklund304
    @nicklund304 6 месяцев назад

    This videos are incredible! I cannot understand what my Java teacher says for the life of me but this makes so much sense! Thank you!

  • @Cablur
    @Cablur 4 года назад +5

    Man, I really was blown away by this amazing tutorial on nested loops! It's sooo damn good! Also I love how easy you explained how to use it to print 2D arrays.
    Thank you so so much! 🥰

  • @arthurivex2298
    @arthurivex2298 4 года назад +1

    I'm using it for an assingment, this really gave me the basis of Nested For Loops. I'm using to create the infamous create words out of phone numbers ie: 2 = ABC, so there is about 2143 different combinations for a 7 digit phone number, and I'm going to use for loops to help with this, I hope. Almost forgot the 2D arrays video also helped in using [ ][ ]{"A", "B", "C"},{"D ", "E ", "F "}, etc. Thank you again!

  • @kkustos
    @kkustos 5 лет назад +1

    Turquoise*
    All secondary colors of light are combinations of the primary colors: Red, Green and Blue. However, the third secondary color of light is Yellow. That's what you get when you combine Green and Red.
    Color and spelling aside, thank you for taking the time to create these videos and for launching your own coding community. I joined the Discord and found the links there very helpful.

    • @alexlorenlee
      @alexlorenlee  5 лет назад

      Kustos that’s great thank you!

    • @sabrinakomm750
      @sabrinakomm750 5 лет назад

      @@alexlorenlee just remember there's no word in the english language, where the letter U doesnt follow Q ;) (ie: queen, quack, etc.)

    • @thelolfrog
      @thelolfrog Год назад

      @@sabrinakomm750 there are many... //when you play scrabble too much...lol

  • @vitocorleone6040
    @vitocorleone6040 3 года назад +2

    Making for loops to find perfect numbers from 1-10000 First intro programming class this shit helped a lot

  • @echiwav
    @echiwav Год назад

    dude i have an exam on nested loops in like 1 hour and you just saved my ass thank you so much

  • @mingchen6229
    @mingchen6229 5 лет назад +19

    It's good, easy to understand. Thanks!

    • @alexlorenlee
      @alexlorenlee  5 лет назад +4

      Ming Chen I’m happy it helped you!

  • @sayed.ahmadmosavi1517
    @sayed.ahmadmosavi1517 4 года назад

    i recently start learning java online to get a job, i do have teacher to teach me but i never understand what he is saying till , but the good things i found your videos on youTube and your way to teach is amazing, you are amazing.

  • @shadmanahmed271
    @shadmanahmed271 4 года назад +3

    Your teaching style is literally very good your videos deserve to be viral in india i tried my best to share your teaching 😊
    Little suggestions: take ur course to udemy

  • @davianbrown6058
    @davianbrown6058 3 года назад +1

    Best java tutorials on youtube!!

  • @lake1495
    @lake1495 Год назад

    This guy is literally teaching me Java more the paid courses very good explaining and makes everything simple a lot of people owe this guy honestly !!

  • @aaronwhite1426
    @aaronwhite1426 Год назад

    I'm using nested for loops for a class assignment. We are given a number of rows and columns. Rows are integers and columns are alphabetical. so the output should list something like this //row1 1A 1B 1C //row2 2A 2B 2C and so on. Pretty difficult for an online class but your videos help a lot. Thanks!

  • @fredericoamigo
    @fredericoamigo 3 года назад +3

    Great vid! Super helpful! You are awesome!
    Since you asked, I'm learning about nested for loops because they're one of the key concepts to get your head around if you want to reach a higher level of programming (in my opinion).
    Furthermore, I would say that nested for loops and nested while loops open up a lot more possibilities - so thanks a lot for this very explanatory video!

  • @BeastReview
    @BeastReview 5 лет назад +7

    I had to check the date on the video when I saw the keyboard he is using

  • @kami6031
    @kami6031 3 года назад +29

    just want this dude to know I’m passing ap comp sci because of him

    • @KR-vu9mo
      @KR-vu9mo 3 года назад +3

      Me too I’ve been winging it for weeks now with no idea how to use for loops thank god for Alex lol

  • @mukulsharma5738
    @mukulsharma5738 4 года назад

    If you do :
    " System.out.println(ArrayName[i].length); ' before nested loop,
    It print's out ..I think the Address of the row before printing it's entries !! Which was very helpfu to me, for understanding what it was actually doing!

  • @jawadalomari6397
    @jawadalomari6397 2 года назад

    when I get a problem in a code, all I need is to check your channel. thank you

  • @serdargayibov8190
    @serdargayibov8190 3 года назад +1

    Thank you so much! It breaks down simple concepts for easier understanding

  • @aishwarya6123
    @aishwarya6123 3 года назад +1

    I absolutely LOVE these! Easy to understand, to the point and helpful. Thanks a lot, Lee!

  • @ghostsalify2796
    @ghostsalify2796 4 года назад +2

    Hey Alex, you're making it a bit too easy.
    AND I LIKE IT!!!

  • @general_pepito
    @general_pepito 3 года назад +1

    Good job man one of the best tutorials I've seen

  • @VirtualVisionStudiosOfficial
    @VirtualVisionStudiosOfficial 5 лет назад +3

    Thanks for this video! I understand for loops so much better and when I go through an array. Studying for a test and didn't quite understand this portion.

  • @nersiyangassan9130
    @nersiyangassan9130 3 года назад +1

    you made it so much easier to me to understand and i hope to pass my test with a great mark😩❤️

  • @prithvimarwadi345
    @prithvimarwadi345 4 года назад +5

    can you make one more video on Multi-Dimensional Arrays,
    to be more specific on " HOW TO VISUALIZE A TABLE MADE using 2d Arrays" ;
    it will be such a relief if i get my doubts clear on that topic
    please!!

  • @enesbasaran821
    @enesbasaran821 Год назад +1

    I'm currently studying at a bootcamp to be a QA Engineer, and we have been learning these during Java Classes. I watch your videos to recap, and It's SUPER beneficial

  • @trevador_2002
    @trevador_2002 5 лет назад +1

    Thanks man I’m in a AP CSA class and you’re clarifying how this works for me and helping me understand better

  • @chandureddy5208
    @chandureddy5208 4 года назад

    Completed Playlist- Java Basics 2 Good videos thanks Alex!

  • @bubble4770
    @bubble4770 5 лет назад +5

    Alex please make a video on pattern program with nested for loops

    • @shavar67
      @shavar67 4 года назад

      bubble channel
      for(int i = 0; i < 7;i++){
      for(int j = 0; j < i;j++){
      System.out.print("*");
      }
      System.out.println();
      }
      Output:
      *
      **
      ***
      ****
      *****
      ******
      Explanation: outer loops executes until the condition is met(i = 7),
      The inner loop executes while j is less than i
      When i = 0
      J = 0
      Increment i to 1
      Now the second time through the loop
      I = 1
      j = 0
      0 is less than one so print an * , increment j to 1 and check the condition again
      1 isn’t less than 1 so we exit that loop and print an empty space,
      Now i = 2
      J = 0
      0 is less than 2 so we print *
      I is still 2
      But now we increment j
      J = 1
      1 is less than 2 so we print another *
      So far the sequence is
      *
      **
      J is now incremented to 2
      Now we check to see if j < i (2

  • @FederikoKorili
    @FederikoKorili 11 месяцев назад

    Dziękujemy za zrobienie tego i innych samouczków java!

  • @CaitlinB0000
    @CaitlinB0000 4 года назад +3

    QOTD... I’m using nested inside nested loops to run a simple word game for kids. I’m still wrapping my head around what I want to accomplish and the logic behind putting together the code to make it happen.

  • @leoulfitness
    @leoulfitness 2 года назад

    Thank you so much for your help! I was using this video to learn how to loop through 2D Arrays.

  • @jadenhuynh5026
    @jadenhuynh5026 3 года назад

    This is my first time watching one of your videos, but I have a feeling that I am gonna watch a lot more this year!

  • @Kav2990
    @Kav2990 5 месяцев назад +1

    I know it's a 5 year old video, but for anyone watching now, it's spelled "Turquoise", and if you use intellij, it has an autocorrect feature

  • @OSAMA-xn1zm
    @OSAMA-xn1zm 3 года назад +5

    I can’t say thanks enough ❤️❤️

  • @kentspencermedez5607
    @kentspencermedez5607 2 года назад

    thank youuu!!!! 🙇🏻‍♂️ now it's clear to me how nested for loops are for 2D arrays 😁 thanks a lot!!!! 🖤🖤🖤

  • @batool3dnan
    @batool3dnan 5 лет назад +3

    this is very helpful! so happy that i found your channel:)

    • @alexlorenlee
      @alexlorenlee  5 лет назад

      BATOOL xx I’m glad you found my channel too! Thank you!

  • @parthsarthi360
    @parthsarthi360 Год назад

    I just like how you use real world examples out there present in the world .... That clears concepts better

  • @Drdominguezc
    @Drdominguezc Год назад

    After watch so many videos, thanks to this one i finally understand it... Thank you!!!

  • @trex_7
    @trex_7 3 года назад

    simple tutorial ezzzz java , thanx man

  • @kaleido6096
    @kaleido6096 3 года назад +1

    Alex you must be an angel in disguise... Thank you thank you thank you soooo much because I thought that I’d never understand this! I’m really happy right now!!

  • @coolboy.bladersshow9159
    @coolboy.bladersshow9159 3 года назад

    Thanks bro!!!! I had a lot of confusion but you helped me understand it easily.

  • @IrrelevantOracle
    @IrrelevantOracle 2 года назад

    Seeing this video for learning purpose. I appreciate your efforts. Keep it UP!!

  • @FriedRice3519
    @FriedRice3519 4 года назад +1

    Next time can you please do a video on nested for loop example questions and go through them? It will be very helpful since I've been having trouble in computer science class

  • @anaraydamir
    @anaraydamir Год назад

    everything is great .Thank you Alex! I think Length method would be more easier because sometimes we can have a lot of rows and column

  • @saikarthikmannava4045
    @saikarthikmannava4045 5 лет назад

    Thank you Alex!, watched so many videos but only understood after your video. It was a great help. Please make videos on Sorting and Searching Algorithms in java. Waiting for those videos.

  • @cubrain2413
    @cubrain2413 2 года назад

    I use 'nested for loops' for number patterns in school. If you make a video on it, it'll be pretty cool!
    Thanks for the great tutorials!

  • @jacobwestergren8958
    @jacobwestergren8958 4 года назад

    quick question, what is the benefit of doing a 2d array instead of just making a longer normal array? For example, { red, blue, green} {yellow, orange, red} can just be {red, blue, green, yellow, orange, red} and when you want to get an element you can just say colour[2] instead of colour[0] [2].

  • @Slyferrr
    @Slyferrr 2 года назад +1

    Wow you deserve so much more views and subs !

  • @youkeshgurung5280
    @youkeshgurung5280 4 года назад +1

    Thank you so much. You are really a awesome teacher.

  • @WOLF91
    @WOLF91 5 лет назад +4

    Thanks man, do you have a video on sorting, searching, and recursion

    • @alexlorenlee
      @alexlorenlee  5 лет назад +2

      Jairo Poveda not yet, but I probably will in the future

  • @iamsimran2402
    @iamsimran2402 2 года назад

    it helped me with my assignment thanku

  • @ericakay6715
    @ericakay6715 4 года назад +2

    Thank you for sharing your knowledge!You are the best!

  • @himnishdhiman1370
    @himnishdhiman1370 3 года назад

    Alex , I think these nested loops can also be used for a 3d array LiKE This :-
    public class NestedForLoops {
    public static void main(String[] args) {
    String[][][] Array = {{{"Hi" , "Hello" , "Hey"},{"Bye" , "BabBye" , "Bye-Bye"}}};
    for(int i = 0 ; i < 2 ; i++) {
    for(int j = 0 ; j < 3 ; j++) {
    for(int k = 0 ; k < 3 ; k++) {
    System.out.println(Array[i][j][k]);
    }
    }
    }

    }
    }

  • @ZianBhutta
    @ZianBhutta 4 года назад

    Got a nested loops quiz tomorrow and this video is teaching me for it 😂

  • @bran-chex7798
    @bran-chex7798 11 месяцев назад

    Best video opening ever!

  • @talhasiddique2376
    @talhasiddique2376 4 года назад

    Your videos are so helpful I learnt oop following your video. Thanks a lot !

  • @kakashi99908
    @kakashi99908 2 года назад

    I think it is much easier to explain this using regular array syntax instead of the curly braces shortcut

  • @connimii9086
    @connimii9086 3 года назад

    First thing's first cool video and thanks for the help. We had to use nested for loops to create scenes like
    1
    12
    123
    1234
    12345
    123456
    and so on and so forth. I guess this is pretty basic but I also practiced 2d arrays with it.

  • @christopherapuan9968
    @christopherapuan9968 2 года назад

    I am learning this in my programming I class.

  • @Mnuller
    @Mnuller Год назад

    Hey Alex :) In your 2d array - you write for (int i = 0; i < 2 ; i++) - why dont it go out of bounds, seeing that there are only 2 rows? 0 and 1

  • @akizaizayoi4763
    @akizaizayoi4763 5 лет назад +1

    Thanks man. Studying these in advance because my prof is really a terror. Sure, he teaches well. But I feel so scared of him and he makes us do live coding in front(he's a very traditional prof). I'm a slow learner too so I might as well self study via RUclips, Google or any sources outside of school in advance.

    • @alexlorenlee
      @alexlorenlee  5 лет назад +1

      Artillerist X Duelist great idea, that’s exactly what I went through too :/

  • @Backflipmarine
    @Backflipmarine 3 года назад

    Anyone just starting this, I found that the best way to organize my code within one file is to create a new method for each video, that way I can scroll down for easy review.

  • @berceanuflorin9012
    @berceanuflorin9012 3 года назад

    Hello Alex !
    I can't understand this part:
    String[][] fancyColors = { { "Red", "Blue", "Green" }, { "Cyan", "Magenta", "Turqiouse" } };
    for (int row = 0; row < 2; row++) {
    for (int column = 0; column < 3; column++) {
    System.out.println(fancyColors[row][column]);
    }
    }
    Can you explain to me please why in the second loop is "column < 3" and in the forst loop it is "row < 2" ? Because in the both arrays we have 3 elements. Thanks in advance !

  • @MrChevux
    @MrChevux 3 года назад +2

    Hey Alex,
    first of all, your tutorials are great! One question, do you recommend any books for java programming?
    Thanks in advance :)
    Best regards

  • @Don-ts8tp
    @Don-ts8tp 4 года назад +2

    Thank you for the help! Amazing content!

  • @gregoryweb3
    @gregoryweb3 3 года назад

    Thank you lex for the video you shared I learned a lot with your videos especially we are creating chatbot I used some of codes from you

  • @blackTulpan
    @blackTulpan 2 года назад

    Thank you Alex! Cool video
    and cool music!!!

  • @slithivi8763
    @slithivi8763 3 года назад

    How would you make a nested for loop for a 2D Array if you do not know the row and column length?

  • @edouardwilliam2883
    @edouardwilliam2883 2 года назад

    Very helpful sir.....Sir can you do one where you have to calculate the average of 3 numbers using nested for loop using java coding

  • @bigshot_07
    @bigshot_07 4 года назад +1

    Im using nested for loops for making triangular hash pyramid 👀 @alex lee

  • @liangkaijie
    @liangkaijie 3 года назад +1

    Thanks for the tutorials but the music bg is too loudddd..! :))

  • @spidey-yz1vc
    @spidey-yz1vc 5 месяцев назад

    you are A legend

  • @kcconsigo7429
    @kcconsigo7429 4 года назад

    To understand more regarding these loops 😁

  • @kitchentable8529
    @kitchentable8529 5 лет назад +2

    Hey man, can you make a video on do-while loops? I'm working on a project for sh**s and giggles and cont seem to get the loop to work properly.

    • @alexlorenlee
      @alexlorenlee  5 лет назад

      Kitchen Table sure! I have videos planned for a few weeks, but I’ll do while loops after that. I can help you now, and I’ll see if I can give you some advice

    • @kitchentable8529
      @kitchentable8529 5 лет назад +1

      @@alexlorenlee that would be awesome. I'm basically working on a "guess the number" game for practice, that all runs in a do/while loop. is there some way I can send you the code or something?

    • @alexlorenlee
      @alexlorenlee  5 лет назад

      Kitchen Table yea! Send it to my email alexlorenlee@gmail.com and I’ll get your code working

  • @thelilpippin
    @thelilpippin 3 года назад

    Holy shit it's making sense

  • @nerodant85
    @nerodant85 5 лет назад +2

    Thanks Alex!

  • @xdavier31
    @xdavier31 4 года назад

    @ 9:00
    Wouldn't it run 36 times since they're(i & j) less than(

    • @alexlorenlee
      @alexlorenlee  4 года назад +1

      _BlueBlazing_ great question! At first glance it looks like it would, but since we set i to 0, it includes 0, totaling to 5 and 10

  • @yusuphatouray1792
    @yusuphatouray1792 3 года назад

    hi Alex just started watching ur vids....do u do videos of html css and JavaScript?

  • @chonylau6981
    @chonylau6981 4 года назад +1

    Hi Alex, I like your videos a lot. I'm having a class presentation coming soon, and would like to ask you what recording software you are using? Your videos are all crystal clear and the layout is also nice. Thank you in advance.

    • @SkyeVintorez
      @SkyeVintorez 4 года назад +1

      Any vid software will work, you need to,set it in 720p and up for better resolution and quality,,but it takes a lot of File size

    • @chonylau6981
      @chonylau6981 4 года назад

      @@SkyeVintorez Thanks Jefferson, I end up going with OBS.

  • @cactusdg
    @cactusdg 2 года назад

    Thank you ,Alex!

  • @ashvinirewatkar5507
    @ashvinirewatkar5507 4 года назад

    Thanks Alex

  • @dinhomhm
    @dinhomhm 4 года назад

    Thank you and it is very clear,
    I just have a question, what if the rows and columns elements were not the same length,
    when I try it, I get errors with missing output, so how to print it all with no errors?

  • @s_ky03
    @s_ky03 2 года назад

    i have to make an 8x8 alternate 0's and 1's like
    01010101
    10101010...
    for my final exam and its due tmr💀💀
    this vid helped me clear up my understanding of nested loops but i still dont know what to do for the alternating thing🙃

  • @iconiccalico1875
    @iconiccalico1875 4 года назад +28

    turquoise :)

  • @abscodes9587
    @abscodes9587 2 года назад

    turquoise lol. you are a star Alex

  • @moizm2
    @moizm2 3 года назад +1

    I'm using nested for loops for a CS assignment :/

  • @khadijasyed3433
    @khadijasyed3433 3 года назад

    plz show how to save it and where will be that save code

  • @springbahor
    @springbahor 2 года назад

    Thank you Alex

  • @andreacorrales7388
    @andreacorrales7388 3 года назад

    this is fantastic thank you alex