Code Once, Confused Everywhere!" – A Funny Guide to Programming Basics for DSA


Perfect! Here's a solid structure for your basic programming language course that focuses on universal concepts — ideal for starting DSA. You'll write in C++, and I'll provide syntax comparisons for Java, Python, and JavaScript alongside.
1. Input / Output
Concept: Taking input from user and displaying output.
Concept | C++ | Java | Python | JavaScript |
Input | cin >> x; | Scanner sc = new Scanner( System.in ); int x = sc.nextInt(); | x = input() | prompt("Enter value:") |
Output | cout << x; | System.out.println(x); | print(x) | console.log(x) |
- Code
#include<iostream>
using namespace std;
int main() {
int x;
cout << "Enter a number: ";
cin >> x;
cout << "Number you have given: " << x << endl;
return 0;
}
2. Variables & Data Types
Concept: Declaring and storing values.
C++ | Java | Python | JavaScript |
int a = 5; | int a = 5; | a = 5 | let a = 5; |
float f = 5.5; | float f = 5.5f; | f = 5.5 | let f = 5.5; |
char c = 'A'; | char c = 'A'; | c = 'A' | let c = 'A'; |
- Code :
#include <iostream>
using namespace std;
int main() {
string name;
int a = 2;
string b = "ayush basak";
char c = 'y';
float pie = 3.14;
long long pal = 333333333333;
cout << "Hey you! What's your name? : ";
getline(cin, name);
cout << "Collected Variables:\n";
cout << " Name: " << name << endl;
cout << "An int (a): " << a << endl;
cout << "A string (b): " << b << endl;
cout << "A char (c): " << c << endl;
cout << "Value of pie (float): " << pie << endl;
cout << "A long long number: " << pal << endl;
return 0;
}
3. Conditionals (if-else)
Concept: Decision making.
if (x > 0) {
cout << "Positive";
} else {
cout << "Non-positive";
}
Java: Same syntax
Python:
if x > 0:
print("Positive")
else:
print("Non-positive")
JavaScript: Same syntax, but with let
and console.log()
4. Loops (for, while)
Concept: Repetition and iteration.
Loop | C++ | Java | Python | JS |
for | for (int i = 0; i < n; i++) | same | for i in range(n): | for (let i = 0; i < n; i++) |
while | while (x < 10) | same | while x < 10: | while (x < 10) |
- Code :
- For loop :
#include <iostream>
using namespace std;
int main(){
int sum = 0;
for (int i = 0; i < 5; i++)
{
sum = sum + i;
}
cout << sum;
}
- While loop :
#include <iostream>
using namespace std;
int main(){
int i=0;
int sum = 0;
while (i<5)
{
sum = sum + i;
i++;
}
cout << sum;
}
5. Arrays / Lists
This not a data structure just the basic to start out DSA.
Concept: Store multiple values.
C++ | Java | Python | JS |
int a[5]; | int[] a = new int[5]; | a = [1, 2, 3] | let a = [1, 2, 3]; |
- Code :
#include <iostream>
using namespace std;
int main(){
int a[5] = {1, 2, 3, 4, 5};
for (int i = 0; i < a[i]; i++)
{
cout << a[i]<< endl;
}
}
6. Functions
Concept: Reusable code blocks.
int add(int a, int b) {
return a + b;
}
Java:
static int add(int a, int b) { return a + b; }
Python:
def add(a, b): return a + b
JavaScript:
function add(a, b) { return a + b; }
- Code :
#include <iostream>
using namespace std;
int mul(int a,int b){
return a * b;
}
int main(){
int c=mul(2, 3);
cout << c;
}
7. String Basics
Concept: Working with characters.
Operation | C++ | Java | Python | JS |
Declare | string s = "Hi"; | String s = "Hi"; | s = "Hi" | let s = "Hi"; |
Length | s.length() | s.length() | len(s) | s.length |
- Code :
#include <iostream>
using namespace std;
int main(){
string a = "ayush";
int b = a.length();
cout << b;
}
8. Basic Examples
Print 1 to 5
for (int i = 1; i <= 5; i++) cout << i << " ";
Java: Same
Python: for i in range(1, 6): print(i, end=" ")
JS: for (let i = 1; i <= 5; i++) console.log(i);
9. Start DSA with These Topics
Arrays (1D & 2D)
Strings
Functions (Recursion)
Sorting & Searching
Pointers (in C++)
STL (
vector
,set
,map
) or Collection for Java.Classes & OOP Basics
Final Tip
Focus on concepts, not syntax.
Syntax changes, logic stays.
Here is the Repo for the Basic of All language that You will need .
Subscribe to my newsletter
Read articles from the_OldSchool_coder directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

the_OldSchool_coder
the_OldSchool_coder
I am a passionate full-stack web developer with expertise in designing, developing, and maintaining scalable web applications. With a strong foundation in both front-end and back-end technologies, I specialize in creating dynamic user experiences and robust server-side solutions. Proficient in modern frameworks like React, Angular, Node.js, and Django, I thrive on crafting efficient, clean code and optimizing performance. Whether building RESTful APIs, designing responsive interfaces, or deploying applications to the cloud, I bring a results-driven approach to every project.Let me know if you'd like to customize it further, perhaps including your specialties or experience level!