369 TESLAKALVIYOGI
Page 28 of 30

Loop with Condition

Printing even numbers / multiplication table

</> logic
1

Concept Meaning

A loop with condition repeats steps and prints only selected values based on a rule.

2

Real-Life Analogy

Teacher asks students to write only even roll numbers or the 5 times table.

3

Expected Output

Even numbers: 2 4 6 8 10
4

Common Mistake

Condition selects the output. Wrong condition gives wrong values.

Same Logic • Different Syntax

Code in 4 Languages

JavaScript
for(let i=1;i<=10;i++){
 if(i%2==0) console.log(i);
}
C++
for(int i=1;i<=10;i++){
 if(i%2==0) cout<<i<<endl;
}
Python
for i in range(1,11):
    if i%2==0:
        print(i)
PHP
<?php
for($i=1;$i<=10;$i++){
 if($i%2==0) echo $i."<br>";
}
?>

Memory Tip

Loop repeats. Condition selects.