Create Your First Functional Component in React JS – Beginner's Guide

Image
Create Your First Functional Component in React JS  1. Introduction When you start learning React JS, one of the first things you will come across is the concept of components. At first, components may seem like just another programming concept, but they are actually the foundation of almost every React application. Think about a website you use every day. It may have a header, navigation menu, login form, product section, and footer. Instead of writing all these elements together in one large file, React allows us to create separate parts and manage them independently. These separate parts are called components. In this tutorial, we are going to create our first functional component in React. We will start with a very simple example and gradually understand how components are created, exported, imported, and displayed on a webpage.  2. What Is a Functional Component in React?   A functional component is simply a JavaScript function that returns a user interface using JSX...

What is PHP While Loop? Syntax, Examples

 PHP While loop

PHP While Loop Explained – What, Syntax, and Real Examples

1]   While Loop in PHP  can be used to  repeat the same process

2]   The while loop repeats a block of code until the condition is FALSE. 

3]   Exit the body loop when the condition is FALSE.

4]   This loop should be used if the number of iterations is unknown.

5]   Entry-controlled loop because the condition is checked before entering the loop body. 

6]   This means checking the condition first. If the condition is true, the code block is executed.

What is PHP looping concept ?

The PHP while loop is used to execute a block of code repeatedly as long as a specified condition is true. It checks the condition first, and if the condition evaluates to true, the code inside the loop runs. This process continues until the condition becomes false.

Syntax :-

php while loop


Flowchart :-

PHP while loop /output


Why PHP While Loop is Important?

✔ Helps automate repetitive tasks
✔ Saves time and reduces manual coding
✔ Works well when the number of iterations is unknown
✔ Makes code cleaner and more efficient

What is PHP While Loop? Syntax, Examples


When to Use While  looping concept

ஃ  You don’t know how many times the loop should run
ஃ  The loop depends on a condition
ஃ  You need dynamic execution based on user input or data

how while loop works in PHP 

✅  The condition is evaluated first
✅   If the condition is true, the code block executes
✅   After execution, the condition is checked again
✅  The loop continues until the condition becomes false

PHP While Loop Example :-


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
<?php
/*decending order in php*/
 $no =10;
 while ($no>0)
 {
    echo $no."<br>";
    $no --;
 }

 /**10,9,8,7,6,5,4,3,2,1 */
 
 
 
?>

</body>
</html>

PHP While Loop OUTPUT :-


10
9
8
7
6
5
4
3
2
1

FAQ (Frequently Asked Questions)

1]. What is a while loop in PHP?
A while loop is used to execute code repeatedly as long as a condition is true.

2]. What is the difference between while and for loop?
While loop is used when iterations are unknown
For loop is used when iterations are known

3]. Can a while loop run forever?
Yes, if the condition never becomes false, it creates an infinite loop.

4]. Is while loop beginner-friendly?
Yes, it is simple and easy to understand for beginners.

Conclusion

The While Loop in PHP  is a powerful and flexible tool for repeating tasks in your code. It is especially useful when the number of iterations is not fixed. By understanding its syntax and usage, you can write more efficient and dynamic PHP programs.

Comments

Popular posts from this blog

HTML Tag

CSS Text Color Explained with Syntax and HTML Examples

CSS Outline Offset Property with Practical Examples