Programming Syntax Cheat Sheet
Version 1.0
STEP NAME LANGUAGE SYNTAX
#include <iostream>
using namespace std;
C++
int Main() {
}
public static void main(String args[])
Java
Start of the Code //All the code should be enclosed inside a class as well
Python No specific start required
<?php
PHP
?>
<script>
Javascript
</script>
int var_1;
C++
char var_2;
public int var_1;
Java
public char var_1;
var_1=2
Declaring a Variable Python
var_2= "This is a string"
$var_1 = 2 ;
PHP
$var_2="This is a string" ;
var var_1=2;
Javascript
var var_2="This is a string";
int function func_01 {
int var_1;
Function/Method Declaration C++
char var_2;
}
public static func_01 {
public int var_1;
Java
public char var_1;
}
def func_01 :
Python var_1=2
var_2= "This is a string"
function func_01 {
var_1=2 ;
PHP
var_2= "This is a string";
}
function func_01 {
var var_1=2;
Javascript
var var_2="This is a string";
}
if (x == 100)
cout << "x is 100";
C++
else
cout << "x is not 100";
if( x < 20 ){
System.out.print("This is if statement");
}else{
Java
System.out.print("This is else statement");
}
}
a=1
If Statement if a > 5:
Python print "This shouldn't happen."
else:
print "This should happen."
if ($t < "20") {
PHP echo "Have a good day!";
}
if (hour < 18) {
greeting = "Good day";
Javascript } else {
greeting = "Good evening";
}
for (int n=10; n>0; n--) {
C++ cout << n << ", ";
}
System.out.print("\n");
For Loop String [] names ={"James", "Larry", "Tom", "Lacy"};
for( String name : names ) {
Java
System.out.print( name );
System.out.print(",");
}
for item in items:
Python print(number, item)
number = number + 1
for ($x = 0; $x <= 10; $x++) {
PHP echo "The number is: $x <br>";
}
for (i = 0; i < cars.length; i++) {
Javascript text += cars[i] + "<br>";
}
cin >> x;
C++
//Takes the value from user and stores in x
Scanner user_input = new Scanner( System.in );
String first_name;
Java
System.out.print("Enter your first name: ");
first_name = user_input.next( );
person = input('Enter your name: ')
Taking Input from User Python
print('Hello', person)
//In PHP taking input from user will need a PHP form
<form action="welcome.php" method="post">
Name: <input type="text" name="name">
PHP
E-mail: <input type="text" name="email">
<input type="submit">
</form>
cout << "Output sentence"; // prints Output sentence on
screen
C++
cout << 120; // prints number 120 on screen
cout << x; // prints the value of x on screen
Java System.out.print( name );
person = input('Enter your name: ')
Python
print('Hello', person)
Write Operation/ Output echo "Hello world!";
PHP
echo "I'm about to learn PHP!";
<h1>My First Web Page</h1>
<p>My first paragraph.</p>
Javascript
<script>
document.write(5 + 6);
</script>
C++ int foo [5] = { 16, 2, 77, 40, 12071 };
Java dataType[] arrayRefVar = new dataType[arraySize];
['red', 'green', 'blue']
[1, 3, 5, 7, 9, 11]
Arrays Python
['silly', 57, 'mixed', -23, 'example']
//These are Python lists
PHP $cars = array("Volvo", "BMW", "Toyota");
Javascript var cars = ["Saab", "Volvo", "BMW"];