Day 05: Unveiling the Magic of INTRODUCTION in Java, C++, Python, and Kotlin!
Tags: data, programming, journey, development
Published: 2024-03-11 05:02:00

DAY - 05
Today’s Learning :- 

For more Tech content Join us on  linkedin [click here](https://www.linkedin.com/in/nitin-bhatt-962356260/)


All the code snippets in this journey are available on my GitHub repository. 📂 Feel free to explore and collaborate: [Git Repository](https://github.com/Nitin-bhatt46/POWER_OF_PROGRAMMING/tree/main
)


Question.

If-else

Two numbers are given, print the bigger number, It is given that both numbers can’t be the same. ( big_num)

Age of a person is given, print Adult if his/her age is greater than 18, otherwise print Teenager. (eligibility)

Take a number in input (ex n) and print the corresponding month to it. Ex: for n=1, print january, n=2, print feburary like this you need to give output. It is given that n will be greater than 0 and less than 13. ( month )

Ticket Price Calculator: Create a program that asks the user for their age and checks if they qualify for a discounted ticket price (e.g., under 12 and over 65 get discounts), If they are eligible print “YES” else “NO”. ( discount_eligible )





There are primarily three types of loops in programming:

For Loop: The for loop is used when you know in advance how many times you want to execute a block of code. It typically iterates over a sequence or a range of values. The loop control variable is initialised, tested against a condition, and updated after each iteration.




While Loop: The while loop is used when you want to execute a block of code as long as a specified condition is true. It continues iterating until the condition becomes false. The condition is evaluated before each iteration.


Do-While Loop: The do-while loop is similar to the while loop, but the condition is evaluated after executing the block of code, so the block of code is executed at least once, even if the condition is initially false.
Example (C++):




A for loop is a control flow statement that allows you to repeatedly execute a block of code a certain number of times or over a sequence of elements. It's useful for iterating over collections, such as arrays or lists, or for executing a block of code a specific number of times.
Here's a general explanation of how a for loop works:
Syntax:
Java:

for (initialization; condition; update) {
 // code to be executed
}

Python:

for item in sequence:
 # code to be executed


C++:

for (initialization; condition; update) {
 // code to be executed
}

Components:

Initialization: This part is executed only once before the loop begins. It initialises the loop control variable.
Condition: The loop continues to execute as long as this condition evaluates to true. If the condition is false at the beginning, the loop won't execute at all.
Update: After each iteration, the update statement is executed. It typically modifies the loop control variable to eventually make the condition false and terminate the loop.


Body: The block of code inside the loop that gets executed iteratively until the condition becomes false.


Example:
Let's consider a simple example where we want to print numbers from 0 to 4:
Java:

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

Python:

for i in range(5):
 print(i)

C++:

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

In each of these examples, the loop starts with i = 0, continues as long as i is less than 5, and increments i by 1 after each iteration. Inside the loop, the value of i is printed. The loop iterates 5 times, printing the numbers from 0 to 4.
This is a basic explanation of the for loop syntax and how it works across different programming languages. It's a powerful tool for repetitive tasks and iteration.


Feel free to share this post to enhance awareness and understanding of these fundamental concepts in statistical analysis!
 



🙏 Thank you all for your time and support! 🙏
Don't forget to catch me daily at 10:30 Am (Monday to Friday) for the latest updates on my programming journey! Let's continue to learn, grow, and inspire together! 💻✨