Skip to player
Skip to main content
Skip to footer
Search
Connect
Watch fullscreen
Like
Comments
Bookmark
Share
Add to Playlist
Report
Learn Programming Technique C to Master Skills - Loop Within Loop Program
Tutorials Arena
Follow
10/17/2024
Category
📚
Learning
Transcript
Display full video transcript
00:00
Hello everyone in my last video I have explained that how loop within loop works in a flow
00:09
chart.
00:11
So we have understand this program that to display 1 then to 1 2 and 2 and to 3 in flow
00:18
chart.
00:19
Today I am going to implement this program in C with the help of code blocks.
00:27
I am going to make the program in C, let me open the code blocks and inside it I am going
00:34
to create a new file.
00:41
I will include the header file that is https://stdio.h I will save it also, I will click
00:51
on the save file, give it a name to it loop1 and then choose save as type cc++ files and
01:02
then save.
01:05
I will use int main and inside it I will take two variables one is i another one is j.
01:17
I will apply the outer loop that will work for rows.
01:22
So i equal to 1, how many rows that is 3 rows, if we see the flow chart also we need 3 rows
01:33
1 then 2 then 3.
01:37
On the basis of that here I have used what i equals to 1, i less than equals to 3 then
01:47
i++ and the inner loop I will apply for the columns.
01:56
Here I have to think that what logic should I apply so for here j equals to 1 and I compare
02:06
inner j with i, j i less than equals to i and then j++, we will do the dry run and see
02:17
is it working fine or not.
02:20
Once it will come to the inner loop and as I applied I will display the value of j that
02:28
is I will use the specifier %e, j.
02:34
I need some space also after printing of the value so I will use what slash t for giving
02:47
a distance and here after the inner loop outside of the inner loop I will use printf and use
02:58
what slash n to take the cursor on the next line.
03:04
So this is the program friends of printing 1 then 1, 2 then 1, 2, 3 of loop within loop.
03:13
Let us save it first I am going to file and clicking on save file.
03:19
First thing what I will do I will click on the build so it's showing me 0 errors, 0 warning.
03:27
Now let us run and see is it going to display yes 1 then 1, 2 then 1, 2, 3 so we got the
03:35
correct result so how the things are working let us see how the loop within loop works
03:42
let us see how it's going to print 1 then 1, 2 and 1, 2, 3 let us see.
03:47
So here I have taken two variables i and j this loop is the outer loop which is going
03:54
to represent for the rows and this one is the inner loop which is going to represent
04:00
for the columns okay.
04:02
So the value of i is 1 okay it will come to the descent part 1 less than 3 the condition
04:09
is true immediately it will come to the inner part inner loop what is the value of j it's
04:15
1, 1 less than equals to i that is 1 equal to 1 so it's going to print the value of j
04:23
that is what 1 so 1 is going to print and some space is also going to print after printing
04:30
1 okay so once it will complete the value of j is going to increment so now the value
04:39
of j will be what 2 it will come to the decision part 2 less than 1 the condition will get
04:46
false once the condition will get false this inner loop will terminate and it will come
04:53
to the outer loop once it will come to the outer loop before that we have used the slash
04:59
n so the cursor is going to move to the next line or the next row okay so it will take
05:07
the cursor on the next row and then the outer loop value of i is going to increment that
05:15
is earlier the value of i was 1 now it's going to increment by 1 so now the value will be
05:22
what 2 it will come to the decision part 2 less than 3 the condition is true and once
05:29
it will come inside the inner loop the way it is going to start the inner loop is going
05:35
to start from its initial value that is j equals to 1 so the value of j is 1 it will
05:41
come to the decision part 1 less than 2 as the value of i is 2 yes so the next line it's
05:48
going to print what 1 okay and the value of j is going to increment okay and now the
05:55
value of j is what 2, 2 equals to 2 the condition is true so after some space it's going to
06:03
print what 2 so in this way the things will work okay and we'll get the results now the
06:15
value of j is going to increment to from 2 to what 3, 3 less than 2 the condition will
06:23
get false this loop will terminate the cursor will come to the next row okay the value of
06:30
i is going to increment by 1 that is what now the new value of i will be what 3, 3 equals
06:38
to 3 the condition is true again it will come to the inner loop now this time the value
06:43
of i is 1 it will start from its initial value and what is the value of i it's 3 so 1 less
06:50
than 3 the condition is true so first the value of j is going to print that is not 1
06:57
okay with some space after that some space and the value of j is going to increment that
07:03
is what 2, 2 less than 3 so the 2 is going to print and then after it some space then
07:10
the value of j is what 3, 3 equal to 3 so what 3 is going to print and after it some
07:18
space then the value of j is what 4, 4 less than 3 the condition will get false the inner
07:24
loop will terminate it will come out the cursor will going to come on the next row and it
07:30
will go into the outer loop where the value of i is going to increment from 3 to what
07:34
4, 4 less than 3 so the outer loop will also gets terminate it will get the result so let
07:43
us run it and see it's showing the result okay so I hope you understand how the loop
07:51
will loop works in my next video I am going to explain something else thanks for today.
Recommended
10:56
|
Up next
Learn Programming Technique C to Master Skills - Loop With If Statement Program
Tutorials Arena
10/13/2024
5:02
Learn Programming Technique C to Master Skills - Third Program of Loop
Tutorials Arena
10/17/2024
3:51
Learn Programming Technique C to Master Skills - First Program of Loop (For Loop)
Tutorials Arena
10/13/2024
3:55
Learn Programming Technique C to Master Skills - First Program of Loop (While Loop)
Tutorials Arena
10/13/2024
4:03
Learn Programming Technique C to Master Skills - Second Program of Loop ( For Loop )
Tutorials Arena
10/17/2024
8:07
Learn Programming Technique C to Master Skills - Loop with if Statement Second Program
Tutorials Arena
10/17/2024
4:07
Learn Programming Technique C to Master Skills - Second Program of Loop (While Loop)
Tutorials Arena
10/17/2024
4:28
Learn Programming Technique C to Master Skills - Fourth Program of Loop ( For Loop )
Tutorials Arena
10/13/2024
5:33
Learn Programming Technique C to Master Skills - Fourth Program of Loop ( While Loop )
Tutorials Arena
10/13/2024
8:18
Learn Programming Technique C to Master Skills - Loop Within Loop Program Explanation in Flow chart
Tutorials Arena
10/17/2024
4:57
Learn Programming Technique C to Master Skills - Loop With If Statement Program ( Flow Chart )
Tutorials Arena
10/13/2024
12:06
Learn Programming Technique C to Master Skills - Continuous If Statement Program
Tutorials Arena
10/8/2024
3:51
Learn Programming Technique C to Master Skills - First Program of Loop (Flowchart)
Tutorials Arena
10/13/2024
3:52
Learn Programming Technique C to Master Skills - Second Program of Loop (Flow Chart)
Tutorials Arena
10/17/2024
3:27
Learn Programming Technique C to Master Skills - Third Program of Loop ( Flow Chart)
Tutorials Arena
10/17/2024
9:12
Learn Programming Technique C to Master Skills - Program of Recursion
Tutorials Arena
11/6/2024
3:02
Learn Programming Technique C to Master Skills - Linked List Program - Recursive
Tutorials Arena
12/2/2024
3:40
Learn Programming Technique C to Master Skills - Array of Pointer Program
Tutorials Arena
11/9/2024
9:20
Learn Programming Technique C to Master Skills - Union Program
Tutorials Arena
11/10/2024
7:56
Learn Programming Technique C to Master Skills - Nested If Statement Program
Tutorials Arena
10/12/2024
12:22
Learn Programming Technique C to Master Skills - Bubble Sort Program
Tutorials Arena
10/20/2024
6:17
Learn Programming Technique C to Master Skills - Circular Linked List Program
Tutorials Arena
12/2/2024
4:57
Learn Programming Technique C to Master Skills - Loop with If Statement Second Program Continue...
Tutorials Arena
10/17/2024
4:55
Learn Programming Technique C to Master Skills - Linked List Program
Tutorials Arena
12/2/2024
4:22
Learn Programming Technique C to Master Skills - Pointer And Arrays Program
Tutorials Arena
11/9/2024