#19 For Loop in Java
HTML-код
- Опубликовано: 3 ноя 2024
- Check out our courses:
Enterprise Java Spring Microservices: go.telusko.com...
Coupon: TELUSKO10 (10% Discount)
Master Java Spring Development : go.telusko.com...
Coupon: TELUSKO20 (20% Discount)
For More Queries WhatsApp or Call on : +919008963671
Udemy Courses:
Spring: go.telusko.com...
Java:- go.telusko.com...
Java Spring:- go.telusko.com...
Java For Programmers:- go.telusko.com...
Python : go.telusko.com...
Git : go.telusko.com...
Docker : go.telusko.com...
website : courses.telusk...
In this lecture we will learn:
Overview of a while loop
For loop and its point
Syntax of for loop
Nested for loops
#1
-In the while loop we have three things: Initialization, Condition, and then increment.
-We do these three things in different lines in a while loop.
-Sometimes we do not know about the ending point, where this loop will get end. As it may end based on some conditions.
#2
In the finite loop, we know about its starting and ending.
For loop supports three different statements in one line.
We can put initialization, condition and increment in one single line in for loop.
It is mostly used when the number of iterations is fixed.
Because of the binary format computer starts from 0.
So, in general, we start from 0 and end at count-1 ie., one less than the total number of iterations.
Loops are very useful when we have to print some pattern or want to print things repeatedly.
#3
Syntax of For Loop:-
for(initiation; condition; incrementation or decrementation)
{
statements;
}
init - The init expression is used for initializing a variable, and it is executed only once.
condition - It executes the condition statement for every iteration. If it evaluates the condition to be true, it executes the body of the loop. The loop will continue to run until the condition becomes false.
incr/ decr - It is the increment or decrement statement applied to the variable to update the initial expression.
First initiation and condition statement execute and then execution of statements takes place and then increment takes place at last.
We can also skip any of the three parts as per the need.
#4
Nested For loops:-
We can also use nested for loops as same as while loop. Nested loops mean loop inside a loop.
Whenever the outer loop meets the condition, the inner loop is executed completely.
Github repo : github.com/nav...
Java:- bit.ly/JavaUde...
Spring:- bit.ly/SpringU...
More Learning :
Java :- bit.ly/3x6rr0N
Python :- bit.ly/3GRc7JX
Django :- bit.ly/3MmoJK6
JavaScript :- bit.ly/3tiAlHo
Node JS :- bit.ly/3GT4liq
Rest Api :-bit.ly/3MjhZwt
Servlet :- bit.ly/3Q7eA7k
Spring Framework :- bit.ly/3xi7buh
Design Patterns in Java :- bit.ly/3MocXiq
Docker :- bit.ly/3xjWzLA
Blockchain Tutorial :- bit.ly/3NSbOkc
Corda Tutorial:- bit.ly/3thbUKa
Hyperledger Fabric :- bit.ly/38RZCRB
NoSQL Tutorial :- bit.ly/3aJpRuc
Mysql Tutorial :- bit.ly/3thpr4L
Data Structures using Java :- bit.ly/3MuJa7S
Git Tutorial :- bit.ly/3NXyCPu
Donation:
PayPal Id : navinreddy20
www.telusko.com
🎯 Key Takeaways for quick navigation:
00:13 For loops provide a concise way to initialize, conditionally iterate, and update a counter variable in one line.
01:55 The for loop syntax allows you to combine initialization, condition, and increment/decrement statements in one line, separated by semicolons.
02:22 Make sure to set the initial value correctly, as the loop will not run if the initial value doesn't meet the condition.
03:15 You can start the loop at zero, but be mindful of the ending condition to ensure the desired number of iterations.
04:51 Common practice is to use "less than" condition for loops that start from zero and end before a specific value.
06:42 Nested loops can be used to create patterns or print structured data, like days and hours in a calendar.
08:47 When concatenating numbers and strings, use parentheses to ensure proper mathematical operations.
10:10 Be cautious when setting loop conditions involving numbers and time intervals, ensuring accurate ranges.
11:19 For loops execute the initialization, condition check, and increment/decrement sequentially for each iteration.
12:56 It's possible to skip parts of the for loop structure and perform necessary operations outside the loop if needed.
Made with HARPA AI
Excellent💯😃
But what do you mean by barpa Al
??
@@AnuragRawat01 this timestamp given by harpa_ai
The summary was made using Harpa AI online service @@AnuragRawat01
Please sir make Data Structure and Algorithm Course in Java.
11:30
first it will pick i value
second it will check the condition 1
🎯 Key Takeaways for quick navigation:
00:00 🔄 *For Loop Introduction*
- Introduction to the for Loop in Java.
- Comparison with while loop structure.
- Overview of initialization, condition, and increment statements in for Loop.
01:13 🔄 *For Loop Syntax*
- Explanation of combining initialization, condition, and increment statements in a single line.
- Differentiating for Loop from while loop regarding this syntax.
- Practical demonstration of a simple for Loop example.
02:35 🔄 *Working of For Loop*
- Understanding the execution flow of for Loop.
- Demonstrating the role of initial value, condition check, and increment in a for Loop.
- Practical example of printing values in both increment and decrement order.
04:51 🔄 *Common For Loop Syntax*
- Introduction to a common syntax for for Loop with initialization, condition, and increment statements.
- Clarification on using "less than" for ending at a specified value.
- Practical example of printing values starting from zero and ending before four.
05:59 🔄 *For Loop for Building a Calendar*
- Demonstrating a practical example of using for Loop to build a weekly calendar.
- Nested for Loop usage for printing hours in a day.
- Addressing challenges and debugging issues during the example.
11:19 🔄 *Execution Sequence in For Loop*
- Explanation of the execution sequence in a for Loop.
- Debugging demonstration to showcase the order of execution.
- Flexibility to skip the initialization or increment statement in the for Loop structure.
Made with HARPA AI
real-time examples are very confusing sometimes it all messes up , better if you have some prepared examples but really I enjoy your lectures sir and learn something extra !
Sir you are excellent. 😊
Calendar with AM and PM supported :
class Hello {
public static void main(String args[]) {
for (int i = 1; i 12 ? j - 12 : j) + (j >= 12 ? " PM" : " AM") + " - "
+ (endTime >= 12 ? (endTime == 12 ? endTime : endTime - 12) + " PM" : endTime + " AM"));
}
}
}
}
So, I was following your code at the end to make my own kind of Daily Schedule.
public static void main(String a[ ]) {
System.out.println("My weekly school schedule on Java!");
for (int i = 1; i
initialize your k with 0 k=0
I like the high quality video its great
Sir after completing ur whole course did u provide any certificate for completion of course
couldnt you also just make j=9 and j
Instead of adding the j with 8, we can initialize j=9;j
But this gave us different knowledge
thank you
You are awesome!!!
Thanks
sir please do a playlist of dsa with python
Thank you 😊
Awesome, now I'm even more lost.
What if at 2:56 we do
for( i=5; i
it will run forever until it exceeds your memory
You won't be getting any results
What is the need for while loop if for loop uses less space?
I hope, if we know the limit we use for loop. If we don't know the limit (numerical value) we use while loop.
@@durgaraoponnuru17if we know the no of iteration then have to use for right?
@@chaithanyajog4554 Not Sure.. But I guess.
Just came up with without railway time 👍👍
for(int i=1;i
May be you know the syntax & programming logics but your explanation is wrong
क्यों नाराज़ हो रहे, भाई?
for(int j=1;j12?(String.format("%02d",(j-12))):
//String.format("%2d", variable)
//append 0 before single digit
(String.format("%02d",j)))+
":00" + (j>=12? "pm" : "am")+ "-" +
//determine am and pm
(l>12&&l!=24?(String.format("%02d",(l-12))):
//append 0 before single digit
l>12&&l==24?(String.format("%02d",(l=0))):
//12 am becomes 00 am
(String.format("%02d",l)))+
":00"+ (l>11 && l!=24 ? "pm" : "am"));
//12 am excluded
}