BeginnersJava.com -- Java- Lesson 11 -- For loops / nested for loops

preview_player
Показать описание
This is going to be a hard video for a lot of people. I apologize if you struggle with this one. You might want to consider skipping to the next video if you're having too much trouble with this one, as it will likely be easier.

Heavily documented code generated:
Рекомендации по теме
Комментарии
Автор

@VISHMAN14 If you notice our first loop to count upwards we have the following codes: i=0, i<5, i++ and inside of that loop j=1, j<=i, j++. So what the means is as follows: we start with i at 0, and when it gets to 5 it breaks out of the loop since it's not longer satisfied. Then each time through the loop, i increases by 1. Now, the inner loop is a little different. The inner loop counts from 1, up to i each time i goes up. Therefore our actual loop variables will look something like..

BeginnersProgramming
Автор

new to java, learning loops, liked the tutorial. (did full screen). Loops a bit confusing at this beginning stage; will keep practicing.

TheChrlmgn
Автор

@VISHMAN14 The outer loop iterates first, before the inner loop begins. Therefore, the outer loop becomes 1 from 0 due to it's increment condition before the inner loop has done anything. Then the inner loop begins it's work.

dgmcnaught
Автор

@VISHMAN14 i=1, j=1, output one, inner loop breaks, outerloop iterates to 2. i=2, j=1, j outputs 1, counts up to 2, outputs 2, and breaks because 2 is equal to i. i iterates up to 3. i=3, j=1, j outputs one, then increases to 2, checks to see if 2 <= i and it is, so 2 outputs, loops again increasing to 3, checks to see if it's < or equal to, and it is, so it outputs 3, iterates to 4, and breaks. Etc etc etc. That's the basic idea of how nested loops work.

BeginnersProgramming
Автор

@Solara989 Sure, why not? The code would have to be altered a bit, but the basic idea is the exact same as the one in this video.

BeginnersProgramming
Автор

Well, I'll do you one better. If you go and watch either video.... 3 or 4 in this series, I show you how to use the debugger. Once you watch that video you can step through each line of code and see what it's doing. The basic idea is this though.... (Continued in the next post for space sake)

BeginnersProgramming
Автор

@VISHMAN14 Well, I'll do you one better. If you go and watch either video.... 3 or 4 in this series, I show you how to use the debugger. Once you watch that video you can step through each line of code and see what it's doing. The basic idea is this though.... (Continued in the next post for space sake)

BeginnersProgramming
Автор

@aklilu2 Change quality to 720p, fullscreen.

BeginnersProgramming
Автор

@SkyeShatter

Thanks for the explanation, but i still dont understand. The outer loop shouldnt iterate until the inner loop is finished right? If thats true i = 0 when it enters the nested loop, but since j = 1, and j > i, and not <= i, the program shouldnt even work. I just cant wrap my head around this.

VISHMAN
Автор

@SkyeShatter what kind of alteration I should do to make it work?

AyaAljanabi
Автор

Can you explain how the loop is getting that output? Like go through each iteration? Nobody explains how the loop actually gets that out output in every video ive seen.

VISHMAN
Автор

@790102078 Not sure if trolling.... Change settings to 720p, fullscreen, will look wonderful.

BeginnersProgramming
Автор

can u create staircase using rectangles

AyaAljanabi