Course එකට ආපසු

Syntax vs Logic

20 මිනිත්තු📖Lecture

Syntax vs Logic Explained

YouTube Video

🎯 Lesson Objectives

By the end of this lesson, you will:

  • Clearly understand the difference between syntax and logic
  • Know which one AI handles and which one you handle
  • Feel confident about your role in the coding process

📖 Introduction: The Two Parts of Programming

Every program, from a simple calculator to a complex app like Instagram, is made of two things:

  1. Logic — What the program should DO
  2. Syntax — HOW to write it in code

Understanding this difference is key to becoming an effective vibe coder.


🧠 What is Logic?

Logic Defined

Logic is the thinking part of programming. It's about:

  • What problems need to be solved
  • What steps to take to solve them
  • What should happen when certain conditions are met
  • How data should flow through the system

Logic Examples in Real Life

SituationLogic Involved
Making a sandwichBread first, then ingredients, then bread on top
Crossing a streetCheck for cars, wait if needed, then walk
Setting an alarmCalculate when to wake up, set time, enable alarm
Planning a routeFind destination, check options, choose fastest

Logic in Programming

Here's the LOGIC for a simple password checker:

1. Ask user for password 2. Check if password matches stored password 3. If it matches → Grant access 4. If it doesn't match → Show error 5. If wrong 3 times → Lock account

This is pure logic. No code syntax yet!


📝 What is Syntax?

Syntax Defined

Syntax is the grammar of programming languages. It's about:

  • The exact words and symbols to use
  • Where to put brackets, semicolons, and quotes
  • How to format the code correctly
  • The specific rules of each programming language

The Same Logic, Different Syntax

Remember the password logic? Here's how it looks in different languages:

Python
# Python syntax
password = input("Enter password: ")
if password == "secret123":
print("Access granted!")
else:
print("Access denied!")

Notice: The LOGIC is identical in all three. The SYNTAX is completely different!


🎯 Who Does What?

Your Job (Logic)
AI's Job (Syntax)
Decide what the program should do
Write the actual code
Define the steps and sequence
Choose correct keywords
Specify conditions and rules
Place brackets and semicolons
Describe desired behavior
Format code properly
Review if output is correct
Handle language-specific rules

🎮 Practice: Logic or Syntax?

Let's test your understanding! For each item, decide if it's a Logic concern or a Syntax concern:

Mark each as Logic (L) or Syntax (S)

0/8

💡 Why This Matters for Vibe Coding

The Key Insight

When you prompt AI, you focus on the LOGIC. You describe:

  • What you want to happen
  • What conditions should trigger actions
  • What the user experience should be

AI translates your logic into proper syntax for whatever language you're using.

Example Prompt

Good Prompt (Focus on Logic)
Create a password checker that: - Asks the user for a password - Checks if it matches 'secret123' - Shows 'Access granted!' if correct - Shows 'Access denied!' if wrong - Locks after 3 failed attempts
ChatGPTClaude

💡 Tips:

  • Notice how we describe WHAT should happen
  • We don't specify HOW to write the code
  • AI will figure out the syntax

🚫 Common Mistake

Don't Mix Logic and Syntax in Prompts

Bad Prompt: "Make a function called checkPassword that uses an if statement with triple equals and console.log for output"

Why it's bad:

  • You're trying to dictate syntax
  • AI might know better approaches
  • You're limiting AI's capabilities

Good Prompt: "Create a password checker that validates user input against a stored password"

Why it's good:

  • Focuses on the outcome
  • Lets AI choose best implementation
  • Clear about what it should DO

🧠 Analogy: The Translator

Think of AI as a translator:

  • You speak: "I want a red button that says 'Click me' and shows a popup when clicked"
  • AI translates to: HTML + CSS + JavaScript code

Just like you don't need to know French to have a translator help you in Paris, you don't need to know programming syntax to have AI help you build software.

Your job is to know what you want to say. AI's job is to say it in the right language.


✅ Lesson Summary

Logic (Your Focus)
Syntax (AI's Focus)
WHAT should happen
HOW to write it
Problem-solving
Code formatting
User experience
Language rules
Conditions and flow
Keywords and symbols
Requirements and goals
Implementation details

Remember: You bring the ideas. AI brings the code.


📝 Mini Quiz

📝 Check Your Understanding

1/3

Which of these is a LOGIC concern?