Skip to main content

FOR LOOP EXAMPLE IN C LANGUAGE

Simple example on how "for loop" works.
Syntax:


for( initialisation ; condition ; incrementation or decrementation) {  }
  1. Initialisation  - Initialise any value
  2. Condition - Basically its till when the loop should continue. (Ex: number < 10)
  3. incrementation or decrementation : To increment or decrement any value.
Example to print 10 even numbers.

#include<stdio.h>
int main()
{
int num;
for(num=0;num<10;num++) //Repeat this block 
{
         if(num%2 == 0)
         {
            printf(" %d ",num);
         }
}
return 0;
}

Output:
0 2 4 6 8

Description:
In this example is same as while loop.We first repeat some block of statements till the value of "num" variable reaches to 10.Then we check if the current number is even and print it.

for(num=0;num<10;num++) { }- this statement  first assigns zero value to num.

Step 1:Then condition is checked.Pointer then enters the for loop block if condition is true / satisfied.

Step 2:It then executes everything inside the block as long as condition is satisfied.

Step 3:Then after the block is executed once value of num gets incremented.

Step 4: Then if condition is true Step 1 is repeated. If condition is false then pointer comes out from the for loop.

if(num%2==0) - This statement means that when number is divided by 2 then remainder is zero. This is simply to check if value in "num" variable is even or not.

num++ : This means num = num +1;
Description in marathi /рдорд░ाрдаीрдд рд╡рд░्рдгрди:

рд╣ा while loop рдЪा рдЙрджрд╣рд░рдг рдЖрд╣े. рд╣्рдпा рдЙрдзрд░्рдиाрдд рез рддे резреж рдЕंрдХाрди рдордз्рдпे even numbers (2,4,6,8,10......) рдХोрдг рдХोрдгрддे рдЖрд╣े рддे рдиिрд╡рдбрд▓े рдЖрд╣े.

for(num=0;num<10;num++) - рд╣्рдпाрдд рей рдШрдЯрдХ рдЖрд╣ेрдд.
рез - рдкाрд╣िрд▓ांрджा "num" рд▓ा рд╢ुрди्рдп рдХिंрдордд рдард░рд╡рд▓ी рдЖрд╣े.
реи - рдордЧ рдЕрдЯ рдЕрд╢ी рдЖрд╣े рдХि "num" рдЪी рдХिंрдордд резреж рдкेрдХ्рд╖ा рд▓рд╣ाрди рдЕрд╕рд▓ी рдкाрд╣िрдЬे.
рей - рдЬрд░ рдЕрдЯ рдмрд░ोрдмрд░ рдЕрд╕ेрд▓ рддрд░ рдд्рдпा рдлॉрд░ рд▓ूрдк рдордз्рдпे рдЬे рд▓िрд╣िрд▓ेрд▓ा рдЕрд╕ेрд▓ рддे рд░рди рд╣ोрдгाрд░.
рек - рдлॉрд░ рд▓ूрдк рдПрдХрджा рд░рди рдЭрд▓्рдпाрд╡рд░ "num" рдЪी рдХिंрдордд рез рдиे рд╡ाрдврд╡рд▓ी рдЬाрддे.
рел - рдкрд░рдд рддी рдЕрдЯ рддрдкाрд╕рд▓ी рдЬाрддे. рдЬрд░ рдЕрдЯ рдмрд░ोрдмрд░ рдЕрд╕ेрд▓ рддрд░ рддिрд╕рд░ी рдУрд│(рд╣्рдпा рдкрд░िрдЪ्рдЫेрдж) рдкुрди्рд╣ा рдкाрд│рд▓ी рдЬाрддे.рдкрдг рдЬрд░ рдЕрдХ рдЪुрдХीрдЪी рдЕрд╕ेрд▓ рддрд░ рдкोрдЗंрддрд░ рд▓ूрдкрдЪ्рдпा рдмाрд╣ेрд░ рдпेрддो.

num++ - рд╣्рдпा рдХोрдб рдоुрд│े num рдЪी рдХिंрдордд рез рдиे  рд╡ाрдврддे. (num = num+рез). рд╣ा рдиाрд╣ी рд▓िрд╣िрд▓ा рддрд░ "num" рдЪी рдХिंрдордд рддрд╕ीрдЪ рд░ाрд╣ीрд▓ рдЖрдгि while loop рдЪाрд▓рддрдЪ рд░ाрд╣рдгाрд░.рдо्рд╣рдгूрди рд╣ि рдХाрд│рдЬी рдШेрддрд▓ी рдкाрд╣िрдЬे.

if(num%2==0) - рд╣्рдпा рдХोрдбрдЪा рдЕрд░्рде рдЖрд╣े рдХि "num" рдордз्рдпे рдЕрд╕рд▓ेрд▓्рдпा рдЕंрдХाрд▓ा рдЬेрд╡्рд╣ा реи рдиि рднाрдЧीрддрд▓े рддрд░ рдЙрд░्рд╡рд░िрдд рднाрдЧ(remainder) рд╢ुрди्рдп рдоिрд│ेрд▓. рдЬрд░ рд╢ुрди्рдп рдоिрд│ाрд▓ा рддрд░ рддो "num" even number рдЕрд╕ा рдо्рд╣ंрдЯрд▓ा рдЬाрдИрд▓.

Comments

Popular posts from this blog

IOT : GARDEN WATER SPRINKLER SYSTEM

IoT projects have gained immense popularity due to their ability to leverage the power of interconnected devices and data to create innovative solutions across various domains. IoT projects involve integrating sensors, actuators, and communication technologies to enable the seamless exchange of data between physical devices and the internet. These projects range from simple DIY experiments to complex industrial applications, each offering unique opportunities to transform our lives and improve efficiency. Whether it's creating a smart home automation system, monitoring environmental conditions, optimizing energy usage, or developing intelligent transportation systems, applications of IoT open up a world of possibilities for innovation and connectivity. By harnessing the potential of IoT, we can build intelligent and interconnected systems that revolutionize industries, enhance daily life, and pave the way for a more efficient and sustainable future. In this project we will be using...

POWER BI - THE ARCHITECTURE

Power BI Architecture: A Comprehensive Guide to Building Effective Data Analytics Solutions     Understanding Power BI Architecture: Power BI's architecture comprises four main components, each playing a pivotal role in the data analytics process: Data Sources:   Power BI connects to a wide range of data sources, including databases, cloud services, Excel files, web services, and more. This versatility enables organizations to consolidate their data from various systems into a single dashboard. Data Transformation:   Once the data is sourced, it undergoes transformation and cleaning processes to make it suitable for analysis. Power BI's Power Query Editor provides a user-friendly interface to manipulate, filter, and shape data according to specific requirements. Data Model:   The heart of Power BI's architecture lies in its data model, whic...

TOUCH PLATE BASED DOOR BELL

Title:  Touch plate based door bell  Circuit:  Components: IC 555 Resistors: 1 M, 100k, 330 ohms Transistor: BC547  PN2222A Capacitor: 10n 1 Copper plate : as touch plate. A 6v battery An LED / Ic UM66 Description: This is the simple circuit for touch plate based security system. In this project what basically done is, circuit detects stray voltages produced by mains voltage and electrostatic built  up in the room.If sufficient static voltage is detected by the plate then chip will charge up. Transistor BC 547 or PN2222A is used basically to increase the sensitivity.In place of led just connect IC um 66(melody IC). Applications: In homes, of course. This can be specially used in places like hospitals, when patients need to call doctor by himself.