🔥 **Limited-Time Offer! Get up to 20% OFF on Arduino Metrix products – Shop Now!
public class HelloWorld {
➤ This defines a Java class named HelloWorld. Every Java program must have at least one class.
public static void main(String[] args) {
➤ This is the main method, where the Java program starts running.
System.out.println("Hello, Java!");
➤ This prints "Hello, Java!" to the screen (console).
}
➤ Closes the main method.
}
➤ Closes the class definition.
int a = 10; // Integer variable
➤ Declares an integer variable named a and assigns it the value 10.
String name = "Java"; // String variable
➤ Declares a String variable called name and stores the word "Java" in it.
if (a > 5) { System.out.println("a is greater than 5"); }
➤ An if statement that checks if a is greater than 5. If true, it prints the message.
for (int i = 0; i < 3; i++) { System.out.println(i); }
➤ A for loop that runs 3 times (i = 0 to 2) and prints the value of i each time.
Scanner sc = new Scanner(System.in); // To take input from user
➤ Creates a Scanner object to take input from the user using the keyboard.
#include <iostream>
➤ Includes input-output functions (like cout and cin).
using namespace std;
➤ Lets you use standard names (cout, cin, etc.) without writing std:: every time.
int main() {
➤ The main function where C++ program starts.
cout << "Hello, C++!" << endl;
➤ Prints “Hello, C++!” to the screen.
int a = 10;
➤ Declares an integer variable a with value 10.
string name = "C++";
➤ Declares a string variable name with value "C++".
if (a > 5) { cout << "a > 5" << endl; }
➤ Checks if a is greater than 5, and prints message if true.
for (int i = 0; i < 3; i++) { cout << i << endl; }
➤ A loop that prints numbers from 0 to 2.
return 0;
➤ Ends the main function and returns 0 (success).
}
➤ Closes the main() function.
print("Hello, Python!")
➤ Prints "Hello, Python!" to the screen.
a = 10
➤ Assigns value 10 to variable a.
name = "Python"
➤ Creates a string variable named name.
if a > 5:
➤ Checks if a is greater than 5.
print("a is greater than 5")
➤ Executes if condition is true.
for i in range(3):
➤ A loop that runs 3 times (i = 0, 1, 2).
print(i)
➤ Prints current value of i.
user_input = input("Enter name: ")
➤ Takes input from the user.
print("You entered:", user_input)
➤ Displays what the user typed.
# End of basic Python program
➤ A comment (ignored by Python, used to explain the code).
#include <stdio.h>
➤ Includes the standard input/output library for using printf.
int main() {
➤ The starting point of every C program.
printf("Hello, C!\n");
➤ Prints Hello, C! to the console.
int a = 10;
➤ Declares an integer variable a and assigns 10.
char name[] = "C Language";
➤ Declares a character array (string) with value "C Language".
if (a > 5) {
➤ Checks if a is greater than 5.
printf("a is greater than 5\n");
➤ Prints the result if the condition is true.
}
➤ Closes the if block.
for (int i = 0; i < 3; i++) {
➤ A loop that runs from 0 to 2.
printf("%d\n", i);
➤ Prints the current value of i.
<!DOCTYPE html>
➤ Declares the document type and version of HTML (HTML5 here).
<html>
➤ Root tag of the HTML document.
<head>
➤ Contains metadata, title, and links to styles/scripts.
<title>My First Page</title>
➤ Sets the title that appears in the browser tab.
</head>
➤ Ends the head section.
<body>
➤ Begins the visible part of the webpage.
<h1>Hello, HTML!</h1>
➤ A large heading displayed on the page.
<p>This is a paragraph.</p>
➤ Adds a paragraph of text.
<a href="https://example.com">Visit Site</a>
➤ Creates a clickable link.
</body> and </html>
➤ Closes the body and html document.
fn main() {
➤ Defines the main function — Rust starts execution from here.
println!("Hello, Rust!");
➤ Prints "Hello, Rust!" to the console.
let a: i32 = 10;
➤ Declares an integer variable a with value 10 and type i32.
let name = "Rust Language";
➤ Declares a string variable name.
if a > 5 {
➤ Starts an if statement to check if a is greater than 5.
println!("a is greater than 5");
➤ Prints the message if the condition is true.
}
➤ Closes the if block.
for i in 0..3 {
➤ A for loop that runs from 0 to 2.
println!("i = {}", i);
➤ Prints the current value of i.
}
➤ Closes the for loop.
fn main() {
➤ This is the main function, where the program starts.
println!("Hello, Rust!");
➤ Prints text to the screen.
let a: i32 = 10;
➤ Declares a variable a of type i32 (32-bit integer) and assigns 10.
let name = "Rustacean";
➤ Declares a string variable name.
if a > 5 {
➤ Starts a condition: if a is more than 5…
println!("a is greater than 5");
➤ Prints this message if the condition is true.
}
➤ Closes the if block.
for i in 0..3 {
➤ A loop from 0 to 2 (range is exclusive of 3).
println!("i = {}", i);
➤ Prints the current loop index.
}
➤ Closes the for loop.
<?php
➤ Starts PHP code block.
echo "Hello, PHP!<br>";
➤ Prints “Hello, PHP!” to the browser with a line break (<br> is HTML).
$a = 10;
➤ Declares a variable $a with value 10.
$name = "PHP Language";
➤ Creates a string variable called $name.
if ($a > 5) {
➤ Conditional check: is $a greater than 5?
echo "a is greater than 5<br>";
➤ If true, this line prints the message.
}
➤ Closes the if block.
for ($i = 0; $i < 3; $i++) {
➤ A for loop that runs from 0 to 2.
echo "i = $i<br>";
➤ Displays the value of i on each loop.
}
➤ Ends the loop block.