Total Page Preview:   000000000387

What is for loop in C-Sharp in English and Hindi

 

For loop in C-Sharp in English:

For loop in C# is a type of loop that allows you to execute a block of code repeatedly for a specific number of times. It is useful when you know the exact number of times you want to execute a block of code.

Here's the syntax of a for loop:
 
The for loop has three parts separated by semicolons:
1-Initialization: This part is executed only once at the beginning of the loop. It is used to initialize the loop counter variable.
2-Condition: This part is checked before each iteration of the loop. If the condition is true, the loop continues to execute the code block. If the condition is false, the loop is terminated.
3-Increment: This part is executed after each iteration of the loop. It is used to increment the loop counter variable.
Here's an example of a for loop:

In this example, we have initialized a variable "i" to 1, and then we have used a for loop to print the value of "i" from 1 to 10. Since the condition "i <= 10" is true, the loop will execute repeatedly until "i" becomes greater than 10. The increment part "i++" is used to increment the value of "i" after each iteration of the loop. Once "i" becomes 11, the loop will terminate and control will pass to the next statement in the program.

 

For loop in C-Sharp in Hindi:

For loop C# me ek loop hai jo ki ek specific number of times ke liye ek code block ko execute karne ke liye use kiya jata hai. Yeh loop tab kaam aata hai jab aap exact number of times ko jante hai jisme aap ek code block ko execute karna chahte hai.

For loop ka syntax is tarah hota hai:
 
For loop ke 3 parts hote hai jo semicolon se separate hote hai:
1-Initialization: Yeh part loop ke shuru me ek baar execute hota hai. Isme loop counter variable ko initialize kiya jata hai.
2-Condition: Yeh part har iteration ke pehle check kiya jata hai. Agar condition true hai to loop code block ko execute karta hai. Agar condition false hai to loop terminate ho jata hai.
3-Increment: Yeh part har iteration ke baad execute kiya jata hai. Isme loop counter variable ko increment kiya jata hai.
Yahan ek for loop ka example hai:

Is example me, humne variable "i" ko initialize kiya hai 1 se, aur fir humne for loop ka upyog karke "i" ki value ko 1 se 10 tak print kiya hai. Since the condition "i <= 10" is true, the loop will execute repeatedly until "i" becomes greater than 10. Increment part "i++" is used to increment the value of "i" after each iteration of the loop. Jab "i" 11 ke barabar ho jata hai, tab loop terminate ho jata hai aur control loop ke bahar chala jata hai.

 

 

Thank You

About Author

Brijesh Kumar

Database Developer

I have more then 6 years Experience in Microsoft Technologies - SQL Server Database, ETL Azure Cloud - Azure SQL Database, CosmosDB, Azure Data Factory, PowerBI, Web Job, Azure Function, Azure Storage, Web Apps, Powershall and Database Migration On-Premise to Azure Cloud.
LinkedIn : https://www.linkedin.com



Comments


                           
                           

                           

                           

Facebook User: