Conditional Rendering in React Complete Guide with Examples 2026

Image
  Conditional Rendering in React Conditional Rendering is one of the most useful concepts in React. It means showing different content on the screen depending on a condition. For example: If a user is logged in → show Logout If a user is not logged in → show Login If a student has passed → show Congratulations If a product is available → show Buy Now If data is loading → show Loading... React does not have a separate if rendering tag. Instead, we use normal JavaScript conditions such as if, the ternary operator, &&, and switch to decide what should appear in the UI.

JavaScript for loop

JavaScript For loop



1] for loop :-

  javascript for loop iterates  element for fixed number of time.

Syntax :-

for (initialization; condition; increment)

{

code executed 

}

 initialization  :- is the count variable.

codition :- condition is called  answer is true body than for loop executed.

 condition :- condition is called answer is  false than process stop


1] Example of for loop 

Q. Iterate 1 to 25 print each number.


for (let i = 1; i < 25; i++) {
    console.log(i);
  }
 

 for loop output :-




2] Example of for loop  

Q. Iterate through array and print element.



 fruits=['kiwi','pineapple','watermelon'];
 for(let i=0; i<fruits.length; i++){
    console.log(fruits[i]);
 }

Output 


3] Example of for loop  

Q. Iterate backward form 5 to 0 print.


for (let i = 5; i >= 0; i--) {
    console.log(i);
  }

Output



4] Example of for loop

   Q. for loop run 15 time 


for(let i=0;i<15;i++)
{
  console.log("iteration",i+1);
}


Explain:-

let i=0; initializes loop
counter i to 0
 i<15 condition for loop
 i is less than 15
 i++ increments value i by 1

 prints message display to the
 console.log(iteration , i+1)


Output :-

Related Tutorial :-

javascript variable with example

php program to print alphabet pattern L

css border property

Comments

Popular posts from this blog

HTML Tag

CSS Text Color Explained with Syntax and HTML Examples

HTML Input Type Submit Syntax and Example