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.

c program to display alphabet pattern L with asterisk

                                            C program pattern 

c program to display alphabet pattern L with asterisk


C program to Print  Alphabet  L star pattern 

Example 

#include <stdio.h>

int main() {
    int a,b;
    int n = 7; // height of the L

    for (a = 0; a < n; a++)
{
        for (b = 0; b < n; b++)
{
            // Print * for the left vertical line and the bottom horizontal line
            if (b == 0 || (a == n - 1 && b < n))
{
                printf("*");
            } else {
                printf(" ");
            }
        }
        printf("\n");
    }

    return 0;
}


c program to display alphabet pattern L with asterisk
Explain Program

Step :1

Header

#include <stdio.h>
  •  standard input-output library use functions like printf().

Step :2

Main Function Declaration

int main() {

  • The entry point of the program. Execution starts 

Step :3

Variable Declarations

int a, b;

int n = 7; // height of the L

  • a and b are loop counters.
  • n is the height of the letter L and also the number of rows in the output

Step :4

Outer Loop 


for (a = 0; a < n; a++)

  • Runs from a = 0 to a = 6 
 iteration of this loop correspond to one row of the output

Step :5

Inner Loop (Controls Columns)

for (b = 0; b < n; b++)

  • Run  b = 0 to b = 6 (7 iteration).
  • Each iteration of this loop correspond to one column in the current row

Step :6

.Logic to Print 

if (b == 0 || (a == n - 1 && b < n))


  • b == 0   
  • This is true for the first column in every row, Explanation we print a * in the first column of every row — forming the vertical line of the "L".
  • (a == n - 1 && b < n):
  • This is true only we are on the last row (a == 6) and b < 7 for all columns of the last row.
  • So on the last row, it prints * across the entire row — forming the bottom horizontal line of the "L".
Step :7

printf("*");

Prints an asterisk  the condition is true.

Step :8

printf(" ");

Prints a space

Step :9

printf("\n");

  •  cursor to the next line after printing each row.

C program to Print  Alphabet  L star pattern 
Output


C program to Print  Alphabet  L star pattern


Summary

  • Outer loop: controls rows.

  • Inner loop: controls what to print in each column of the row.

  • Two conditions decide where to print *:

    1. First column (b == 0)

    2. Entire last row (a == n - 1)

Related Post :-

c program to print hollow square star


Comments

Popular posts from this blog

HTML Tag

CSS Text Color Explained with Syntax and HTML Examples

HTML Input Type Submit Syntax and Example