En blidere introduktion til programmering

Denne opskrivning fanger det, jeg underviser, når jeg får coachinganmodninger. Jeg hopper ikke ind i koden eller en opsætning af nogen art. Jeg vil undervise i begreber.

Hvis du arbejder i et softwareudviklingsfirma som ikke-programmør, kan du undre dig over, hvad programmørerne gør. Og du hører nye buzzwords hver dag. Dette indlæg blev skrevet med dig i tankerne. Uanset om du er en sælger, en læge, en advokat, en forretningsleder eller en revisor, hvis du nogensinde har haft det i tankerne at lære at kode, er dette et godt sted at starte.

Hvordan denne artikel er organiseret

Denne opskrivning er opdelt i 4 dele. Efter at have læst igennem hver del finder du et quiz-afsnit, der hjælper dig med bedre at huske, hvad du har læst. Derefter finder du en sektion “fremad” og svar på quizzen.

Bemærk, at hvert buzzword, der introduceres i denne serie, er i fed skrift , f.eks. Algoritme .

Del 1 - Hvad er programmering?

Et simpelt svar ville være, "Programmering er handlingen med at instruere computere i at udføre opgaver." Det kaldes ofte kodning .

Så hvad er et computerprogram ? Et computerprogram er en række instruktioner, som computeren udfører.

Computer i definitionen ovenfor er enhver enhed, der er i stand til at behandle kode. Dette kan være smartphones, pengeautomater, Raspberry Pi, servere for at nævne nogle få.

En god analogi til programmering

For det første er der mønstre i vores hverdagsliv. Universet fungerer på en noget forudsigelig måde; For eksempel - dag og nat, årstider, solopgang og solnedgang. Folk gennemgår rutiner som f.eks. At rejse sig om morgenen, gå i skole eller arbejde. Vi får instruktioner fra andre mennesker som vores overordnede på arbejdspladsen. Hvordan vi laver bestemte opskrifter kan forklares i begrænsede trin.

For det andet, hver gang vi bruger smarte enheder, kører en eller anden kode i baggrunden. At flytte en musemarkør fra den ene del af din computerskærm til den anden kan virke som en simpel opgave, men i virkeligheden løb så mange linjer med kode lige. En handling så simpel som at skrive bogstaver i Google Docs fører til, at kodelinjer udføres i baggrunden. Det hele koder overalt.

Computerprogrammer kaldes også kode . Brug ikke ordet 'koder' (kode skal bruges som et utalligt substantiv). Okay, dette er ikke en engelsk klasse, lad os vende tilbage til forretningen.

Computerens naturlige sprog

Maskiner har deres naturlige sprog som mennesker har. Computere forstår ikke det menneskelige sprog. Computernes naturlige sprog er den binære kode - 1 og 0. Disse repræsenterer to tilstande: til (1) og fra (0) .

Det er det naturlige sprog for elektronisk udstyr. Det ville være hektisk for os som mennesker at kommunikere med computeren i binær.

Indtast programmeringssprog

For at kommunikere med maskiner, der taler binært, gør vi det på et sprog, der er tættere på vores eget naturlige sprog. Såsom engelsk, fransk, swahili eller arabisk. Programmeringssprog er tæt på vores naturlige sprog. Men de er mere strukturerede og skal læres grundigt.

De kunne være sprog på højt niveau eller på lavt niveau. Programmeringssprog på højt niveau er længere væk fra maskinsproget end sprog på lavt niveau. Dette "længere væk" kaldes normalt en abstraktion , men det vil vi ikke gå ind på i denne serie. Lad os ikke blive distraheret :)

Computeren har brug for en måde at forstå vores menneskelige sprog på. For at gøre dette skal vi bruge en oversætter.

Hvad er oversættere?

Kildekode refererer til kode skrevet på et bestemt programmeringssprog. Mere om dette i del 2.

Oversættere har ansvaret for at konvertere din kildekode til maskinens sprog. Dette er også kendt som binært . Husk dem og nuller. Vi henviser muligvis til binærfiler som Objektkode , Programmet eller et almindeligt ord i dag: App .

Oversættere kan være en af:

  • Tolke
  • Kompilatorer
  • En hybrid af tolke og compilers
  • Samlere

Tolke

Nogle sprog fortolkes. Oversætteren behandler kildekoden linje for linje og kører hver linje i det endelige program eller app. Dette betyder, at fortolket kildekode begynder at køre, indtil den støder på en fejl. Derefter stopper tolken for at rapportere sådanne fejl. Mere om dette detaljeret i del 3.

Python er et godt eksempel på et fortolket programmeringssprog.

Kompilatorer

Kompilatorer fungerer forskelligt. De konverterer kildekoden i sin helhed via en kompileringsproces til binær. Binæren udføres derefter. Hvis der var fejl i kildekoden, registreres de i løbet af kompileringstiden og markeres. Dette afbryder kompileringsprocessen, og der genereres ingen binær.

Tolke oversætter linje for linje og udfører linjen, inden de går videre til næste linje. Kompilatorer oversætter alle linjer i et program til en fil (binær) og udfører hele filen.

Husker du definitionen af ​​computerprogram? Det er en række instruktioner, der udføres af en computer.

Et udførelsesprogram kaldes normalt en proces. Sådanne programmer bruger visse ressourcer på computersystemet eller smartphonen, såsom hukommelse, diskplads og filsystemet. Et eksekveringsprogram kan også siges at køre .

Vi bruger ordet 'run', når vi udfører et computerprogram. Den tid, det tager at køre sådanne programmer, er kendt som programets kørselstid .

Det er almindeligt at se programmer kaldet Apps. Vi forbinder også programmer med de platforme eller miljø, hvor de kører, eller er designet til. Der er webapps, der kører på webbrowsere, såsom Google Spreadsheet. Der er mobile apps, som kører på smartphones som CandyCrush. Der er også desktop-apps såsom Evernote desktop-appen.

Igen udføres fortolket kildekode direkte fra kildefilen. Kompileret kildekode konverteres til en binær fil. Den binære fil udføres derefter. Kompileret kildekode mislykkes muligvis under kørselstid, selv efter succesfuld kompilering. Se del 3.

Hybrid oversættere

A hybrid translator is a combination of the Interpreter and Compiler. A popular hybrid programming language is Java. Java first compiles your source code to an intermediate format known as the Bytecode.

The Bytecode is then interpreted and executed by a runtime engine also known as a Virtual machine. This enables the hybrid translators to run the bytecode on various operating systems.

Assemblers

There’s the Assembler as well for translating low-level Assembly language to binary.

For this series, we will only focus on the High level languages.

A good way to look at Translators is to see them as a program in themselves. You need to download or get them, install them on your computer system and understand their basic workings.

An Often Asked Question

Here’s a question beginners usually ask.

Hvilket sprog lærer jeg først?

Der er hundredvis af programmeringssprog. De rangeres efter popularitet, samfund, langsigtet support, pædagogik, forretningsbrug. De kan også rangeres efter tekniske egenskaber, f.eks. Om de er funktionelle, bydende nødvendige, statiske, stærke eller løst typede.

Nogle sprog er mere pædagogiske end andre. Nogle sprog er til uddannelsesmæssige formål og ikke til forretningsbrug. Der er sprog skrevet for eksempel for børn at lære at kode.

Der er meget kraftfulde sprog, der er nemme at opsætte og lære. Python er et sådant programmeringssprog. Jeg anbefaler det normalt til begyndere.

Hvis du er interesseret i at udforske mere om dine muligheder for "første sprog", her er nogle gode undersøgelser foretaget af Philip Guo.

When you want to learn a new language, you know now that you would need that language translator. This is a program you install and setup on your computer system.

I recommend that you start learning how to use a CLI (Command Line Interface). The CLI is the terminal or shell. Think of the terminal as an alternative to a GUI (Graphical User Interface).

In GUIs, you interact with the computer through the mouse pointer. You also depend on visual renditions of directories, and about everything you do.

But, when using a CLI you interact with the computer using commands which you type at the prompt or a blinking cursor

$_

In Windows, the shipped-in terminal is the command prompt. For Mac and Linux users, you already have a default Bash terminal. To get the same experience on Windows, install Git Bash OR PowerShell.

Going Forward

Now that you’ve been mildly introduced to what programming is. You need to prepare yourself for your first line of code :)

To get started you will need the following:

  • A computer system

    At this point, you do not need a sophisticated or very expensive one, you only need a computer that works well.

  • Install the CLI

    I recommend this crash course to get you started on how to use the CLI.

  • Install a text editor

    We will come back to this in Part 2

  • Learn a programming language

    In this series you will learn the basic elements that make up the fundamental knowledge of most programming languages.

Quiz

  • What basic tools do you need to start programming?
  • What command would you use for the following in bash (CLI)?
  • Check your current directory
  • Change to a directory named ‘bin’ (bin is in your current directory)
  • make a new directory called ‘lib’
  • create a new file called ‘book.py’
  • list all the contents the current directory

Summary

We have gone through the basics of programming, with an introduction to Translators. The word “source code” is no longer strange to you. We will examine what a source code is in detail in the next part.

Answers to the Quiz

What basic tools do you need to start programming?

A computer, a text editor, the shell(terminal), and a compiler/interpreter

What command would you use for the following in bash(CLI)?

  • Check your current directory: pwd
  • Change to a directory named ‘bin’ : cd bin
  • make a new directory called ‘lib’: mkdir lib
  • create a new file called ‘book.py’: touch book.py
  • list all the contents the current directory: ls

Part 2 — Source Code

Now that you understand the concept of programming, we will examine source code.

A source code is basically a file, just like a Microsoft (.doc) file, but slightly different. It is a raw text file, written on very simple editors, like the Windows Notepad. You will recall from the previous section that you need either interpreters or compilers to convert your source code to binary. The source code must be saved in a file, which is passed as an input to the translator.

Depending on the language you are writing, there are designated extensions for saving your source code file. Python’s extension is ‘.py’. Java is ‘.java’. Php is ‘.php’ and PERL is ‘.pl’ to name a few.

When you are done writing your source code, you must run it through the translator. As an example, here’s how to run your Python source code using the pythoncommand.

Getting Started: Your First Program

  • Follow the instructions here to setup Python on your computer system.
  • Install a simple editor to type in your source code. You can use sublime text editor for a start.
  • Open a new file on your editor, and type in the following:
print ‘Hello Python!’
  • Remember to save the file as main.py
  • Find the path to the file on your CLI, and type the command below:
$ python main.py

The result should look like this:

The Anatomy of a Typical Source Code

We will now examine the content of a typical source code file. Below are the regular components:

Keywords

Short, human readable words, usually known as keywords. They are peculiar to the language you are learning, and they are special. We’ll come back to this in a jiffy. You need to learn some of the keywords by heart. Here’s the set of keywords recognized and used in Python.

//www.programiz.com/python-programming/keyword-list

Identifiers

Words invented by You — Yes You, the programmer. These words are generally referred to as Identifiers. They could be created by you or other programmers. They are packaged in form of plugins, better known as Libraries.

An example of a library is the Math library. It lets you access functions like the square root (Math.sqrt), used in Javascript.

Many programming languages ship with loads of libraries. These are generally referred to as their SDK s (Software Development Kits). You will download them together with the compiler to start building technologies, apps and projects. Besides these, there are frameworks , designed to help with building on a particular platform such as web or mobile.

Some identifiers are bundled with a language you’re using and may not be used as a user-named identifier. An example is the word string in java. Such identifiers, together with keywords are known as Reserved Words. They are not keywords, but like keywords, they are also special.

All keywords are reserved words, the inverse is not true.

The words you choose should be meaningful to whoever sees them at first glance.

A common use of identifiers is in naming variables , we will look into this in a bit.

Basic Data Types

You will also find data of different types in a source code, numbers (3, 5.7, -100, 3.142) and characters (M, A). In some programming languages, numbers are further broken down into their own types such as integers.

Integers can be Signed or Unsigned , big integers, and small integers. Big or small actually depends on the amount of memory space reserved for such numbers. There are numbers with decimal parts, usually called double and float , depending on the language you are learning.

We also have boolean data types which evaluate to true or false.

Complex Data Types

The data types explained above are known as the elementary, primary or basic data types. We can build more complex data types from these basic data types.

An Array is the simplest form of the complex data type. A String is an Array of characters. We cannot do without these complex data types and often use them when writing our source code.

A combination of characters is a string. To use an analogy, a string is to a computer what a word is to a human being. The word ‘Thermometer’ is made up of 11 characters — we simply call it a string of characters. String processing is a broad topic in itself to learn, and must be studied by every aspiring programmer.

Complex data types are shipped with most programming languages you use. There are others that we build ourselves as programmers, such as the Class systems. These are also known as ( OOP ) Object Oriented Programming.

Variables

Variables are simply named memory locations. We sometimes want to keep data in our source code in a place where we can recall the data, to use again. This is usually a memory location which our compiler/interpreter reserves for us. We need to name these memory locations to recall them later. Consider the Python code snippet below:

pet_name = 'Hippo'print pet_name

pet_name is an example of a variable. Because the type of data stored in pet_name is a string. It is known as a string variable. There are numeric variables as well. Variables are categorized by their data types.

Constants

Constants are values that do not change throughout the lifetime of the program. We use capital letters to enforce that some values are to be constant values. Some languages provide a way to create constant values, while others do not.

Some languages provide the luxury of declaring types that variables should be. We often call these strongly typed languages. Java is a good example.

Others do not provide these features. They are loosely typed or dynamic programming languages . Python is a good example.

Here’s how to declare constant values in JavaScript.

const petName = 'Hippo'

Literals

In every source code, there are data types you use everywhere around your code that will only change if you edit them yourself. We call these literals, which are not to be confused with variables or constants. Literals can be seen once you glance through the source code. They could be strings, numbers, decimals, or other data types.

In the source code snippet above, the word ‘Hippo’ is a literal — a string literal. It will always be ‘Hippo’ until you edit the source code. As you learn to code, you will learn how to manage literals in your source code in a way that is easy to maintain without changing much of your source code.

Punctuations/Symbols

In most source code, you will generally find different punctuation marks depending on the programming language. Java has more punctuation marks, for example than Python.

Common punctuation marks include the comma (,), semi-colon(;), colon(:), braces ({}), Brackets (()), square braces ([]), quotation marks (“ ”), pipe (|), slash (\), period (.), question mark (?), caret(^) and percentage (%).

Welcome to the world of coding, where punctuation marks are your best friends. You will find yourself typing them a lot.

Operators

The chances that you will write code to perform an operation is very high. In the slightest way, you will perform an assignment operation in your source code. We are presented with a large number of operators by the programming languages we use. Examples include addition(+), division(/) multiplication(*), subtraction(-) and greater than(>).

Operators can generally be classified as follows:

  • Assignment Operators

    This is sometimes misconstrued as equal-to. Equal to is used to compare two values. Assignment Operator puts a value in a variable, such as pet_name = 'Hippo'

  • Arithmetic Operators

    Comprises operators for carrying out arithmetic tasks such as addition, and subtraction. Some languages provide some arithmetic operators which others may not have. For example the modulus operator (%) returns the remainder value in division operations.

  • Relational Operators

    are used for comparing values. They include greater than, less than, equal-to, not-equal-to. Their representation varies as well depending on what programming language you are learning. <> is not equal-to in some languages, while in others, it’s != or !==.

  • Logical Operators

    are used to compute logical operations. The commonly used logical operators are and , or , not. Some languages represent these operators with symbols such as && for and , || for or , and ! for not. Logical Operation values usually evaluate to Boolean valuestrue or false.

Comments

Documentation will be an important aspect of your coding activities. It is how you explain your code to other programmers. This is done via comments that are occasionally added to parts of your code. Through comments, you can guide other programmers through what kind of data your code works with and the kind of output that it generates.

Usually, the compiler ignores lines of code that are comments.

Comments vary across languages. The #is used to introduce comments in Python.

Here’s an example of a comment in Python.

# program snippet to compute fibonacci of N numbers

In Java, C and C++ , there are comments for a single line just like the # in Python, but the // symbol is used instead. There are multi-line comments as well /**/. You can read more about comments in the language that you have chosen to learn.

Whitespace and Tabs

These are spaces created between the code you are writing. This is done when you hit the space-bar or the tab key on your keyboard.

Going Forward

Ensure you correctly setup the Python on your computer system, and run your first program.

Quiz

Here’s a simple quiz for you.

Identify the different elements we have studied so far in the Java source code snippet below:

// a recursive implementation of Factorialimport java.util.Scanner;class RecursiveFactorial { public static void main(String[] args) { Scanner input=new Scanner(System.in); System.out.print("Find the Factorial of: "); int num=input.nextInt(); System.out.println("Factorial of "+num+" = "+fact(num)); }
 static long fact(int n) { if(n<2) return 1; return n*fact(n-1); }}

Summary

You have been introduced to what a source code is, and have examined the content of a typical source code.

Compiled or translated, your code might possibly fail to run due to a number of reasons. These reasons are commonly related to errors in your source code. These errors are known as bugs.

The act of finding and removing these bugs is called debugging and is a skill you must learn as a programmer. We will look into what bugs are in the next part.

Answers to the Quiz

Identify the different elements we have studied so far in the Java source code snippet below:

Keywords:

import, class, public, static, void, new, int, long, if, return

Identifiers:

java, util, Scanner, RecursiveFactorial, main, String, args, input, System, in, out, print, println, num, nextInt, fact, n

Literals:

String Literals — “Factorial of ” = “Find the Factorial of: ”

Integer Literals — 2, 1

Operators:

Assignment Operator =

Concatenator + (for joining strings together)

less than &lt;

multiply *

subtract -

Punctuation and Symbols

{ } [] ( ) ; .

Comment

//a recursive implementation of Factorial

Part 3 — Debugging

Once you start trying out code snippets or you are trying to solve actual problems with code, you will soon realize that there will be moments when your program breaks, is interrupted and stops running.

This is often caused by errors, known as bugs or exceptions in run-time. The act of finding and removing bugs from our code is debugging. You get better at debugging code as you try doing it more. We do not only debug our own code, we can also debug code written by other programmers.

To get started, we need to identify the common bugs likely to surface in our source code.

Syntactic Errors

These errors will not allow your source code to compile in compiled programming languages. They are detected at compile-time or during the interpretation of your source code. They can also be detected easily by linters. We will learn a little more about linters later.

They are mostly caused when you break the expected form or structure of the language you are coding in. An example is missing a closing bracket in an equation.

Semantic Errors

Semantic errors also known as logical errors are the most troublesome of all errors. They cannot be easily detected. A sign that there’s a semantic error is when the program runs successfully but does not produce the desired output.

Consider this example:

3 + 5 * 6

By order of precedence, popularly called BODMAS, in Mathematics, we expect the multiplication part to be evaluated first, and then final result will be 33. If the programmer wanted the addition to evaluate first instead, this will give a different output than the desired output. Errors such as this are semantic errors, having more to do with meaning than structure (syntax).

Parenthesis around 3 + 5 will give the desired output of 48 instead.

(3 + 5) * 6

Run-time Errors

Like semantic errors, run-time errors are never detected at compile time. Unlike semantic errors, run-time errors interrupt the program and prevents it from executing further. They are usually caused by unexpected result of some computation within the source code.

Here’s a good example:

input = 25x = 0.8/(Math.sqrt(input) - 5)

The code snippet above will compile successfully, but an input of 25 will result in ZeroDivisionError. This is a run-time error. Another popular example is the StackOverflowError or IndexOutofBoundError. What is really important is that you identify these errors and learn how to deal with them.

There are errors caused by how your source code makes use of memory and space on the platform or environment in which it is run. They are also run-time errors. Such errors as OutOfMemoryErrorand HeapError are usually caused by how much your source code use up resources. A good knowledge of algorithms will help you write code that better makes use of resources.

The process of rewriting your code for better performance is called optimization , and a not-so-related word is refactoring. As you spend more time coding, you should have these in mind as well.

Debugging

Here are a few tips on how to go about debugging your code:

  • Use Linters

    Linters are tools that help read through your source code to check if they conform the expected standard in the language you are coding in. There are linters for many programming languages. Be sure to get one for the language you are learning.

  • IDEs over simple editors

    You could opt for an IDE designed for the language you are learning. IDE stands for Integrated Development Environment. They are software built for writing, debugging, compiling and running code. They usually come with powerful debugging kits, for watching or stepping through your code.

    Jetbrains make great IDEs such as the Webstorm, and IntelliJ. There’s NetBeans, Komodo, Qt editor, Android Studio, XCode (shipped with Mac) to name a few.

  • Reading your code aloud

    This is usually useful when you are looking for a semantic error. While reading your code aloud, there is a high chance you will read out the error as well. That might jump at you as what was probably wrong.

  • Read error logs

    When the compiler flags an error, be sure to look at the line number or the part of your code flagged.

Going Forward

As a beginner, you will be learning to code from books, online tutorials or from videos. You will often type down code as you see them.

Here’s something you should do, when you are done writing or running such code, learn to break them. How do you do this?

Change something to see how the code behaves. Do this so that you don’t make assumption about anything and you are pretty sure you understand what is going on.

Quiz

1 . What’s the likely bug in the Python code snippet below:

items = [0,1,2,3,4,5]print items[8]
//hint: items here is an Array, with 6 items. To retrieve the 4th item for example, you will use items[3]. We start counting from 0.

2. What is the likely bug in the Python code snippet below:

input = Hippo'if input == 'Hippo': print 'Hello, Hippo'

Section Summary

Congratulations! The bug word is no longer a strange one to you, and picking out bugs now should not be either. Next, we will look into the common flow of the code that we write everyday.

Answers to the Quiz

What’s the likely bug in the Python code snippet below:

(1) Runtime Error: Index Out of Range Error

(2) Syntax Error: Missing starting quotation mark on line 1

Part 4 — Basic Coding Flows

Line Of Code, Expressions and Statements

The unit of any source code is the LOC (Line of Code). The simplest program is a line of Code. A LOC could be a keyword, a symbol, or a statement. It’s a Line of Code as long as it’s on a separate line of its own.

Let us consider a simple line of code:

area = 0.5 * base * height

0.5 * base * height is an expression. An expression is a combination of operators and operands. In the example given here, the operands are 0.5, base, height. You will recall that 0.5 is a floating point literal, base and height are variables. The operator is the *(multiplication).

Expressions may not be meaningful staying on their own as a LOC. When we assign the value of an expression to another variable, in the case above the area, what we have is called a statement. It is still a statement when we attach expressions to keywords, example: return 0.5 * base * height

For the rest of this section, we will represent a statement as the symbol S. The nth statement will be Sn amongst a sequence (or set) of statements

To grasp programming quickly, a good starting point is understanding basic coding flows. Basic flows are also referred to as control flows. Once you understand these flows, you will find them in many of the programming languages you learn.

Note that the examples given in this write-up are purely basic. You need to refer to the language you are learning to get an in-depth knowledge of the keywords it provides.

Also the basic flows introduced here are different from design patterns in programming. Understand these basic flows first. You catch up later with common design patterns in programming as you learn more.

Here are the basic programming flows:

  • Sequential
  • Conditional/Branching
  • Iteration/Repetition/Loops

Sequential

This is the most basic flow, where one statement is executed after the other. In the actual sense, every other flow resolves to a sequential flow (more on this later).

S1S2S3...Sn

In some programming languages like JavaScript, it is possible for S3 to execute before S1. This happens if S1 is blocked by some tasks that might take more time such as Data Base or File operations, known as asynchronous tasks. There are ways around cases like this. Not to worry, it will be a breeze to learn when you pick up the programming language to learn.

Conditional/Branching

The statement that executes is determined by conditions. The key keyword here is the if keyword. It’s one of the most used coding flow.

Here’s the simplest conditional pattern:

if (condition) then: S1

In the example above, either S1 executes or nothing happens. S1 is executed only if the condition given is true.

Here’s another conditional pattern:

if (condition) then: S1 S2else: S3 S4

That can be read as either running of S1-S2 or S3-S4 based on the condition given. If the condition is true, S1 and S2 will be processed. Otherwise the statements S3 and S4 will be processed. This in actual sense is a sequential flow:

S1S2

We also have the multi-conditional style:

if (condition1) then: S1else if (condition2) then: S2else: S3

Here if condition1 is true, then S1 is processed. Otherwise condition2 is tested, and if true, S2 is processed. This can go on and on.

For the multi-conditional style, many programming languages provide the switchstatement. Here’s the pattern for the switch statement:

switch value: case condition1: S1 break case condition2: S2 break
default: S3

The condition1 and condition2 are compared with the value in the switch statement. If any of them is true to the value, then the statement in the case block is executed.

There are other choices for conditional flow. Some are specific to the language you decide to learn such as the conditional operator (: ?), and other keywords that facilitate branching such as cycle and break. Be sure to spend sometime understanding the condition/branching flow.

Iteration/Repetition/Loops

The iteration/repetition flow keeps statement(s) running for as long as some conditions are met, and stops executing the statement(s) once the condition is no longer true.

Here’s the pattern:

while (condition): S1 S2

In the example above, statements S1 and S2 may execute once, multiple times, or may not execute at all. If the condition given is true the first time the whilestatement is encountered, then S1 and S2 will be processed. The while condition is checked again, and S1and S2 will be executed for as long as the condition is true.

The moment the condition becomes false the execution of S1 and S2 stops.

The result of statement above if condition is true thrice will be:

S1S2S1S2S1S2

What coding flow is that? If you answered sequential, you are very correct. Still as we can see, the other flows resolve to the sequential flow.

Here’s another iteration pattern:

do: S1 S2while (condition)

In this example, S1 and S2 will execute at lease once or multiple times. This is because they will execute before the condition is tested.

In many programming languages, keywords like the do andwhile are provided for implementing the repetition flow. Another common keyword is the for keyword. Here’s the common pattern for the for statement.

for (initialvalue; condition; decrement/increment initialvalue): S1 S2

Many languages have foreach used for working through each items in a complex object such as an array, or struct.

Quiz

Identify the coding flows in the following Python code snippet:

numlist=[]cnt=0while cnt >= 0: m=int(raw_input()) if m < 0: break numlist.append(m) cnt=cnt+1

Summary

The flows covered here are the basic flows. There’s a way to group a bunch of code together and give them a name. This way you may call this bunch of code whenever you need them at once. This is referred to as a procedure. In the case where the bunch of code perform some operation and return a value, you have a function.

How procedures and functions are implemented vary with different languages. You cannot skip these to get the basics of any language. They are highly important for organizing your code. In fact, this is where the building blocks of your code starts also known as modular programming.

There are other flows that you will learn the moment you understand functions, one that comes to mind is recursion.

Yet, you will find that within procedures and functions are still the awesome coding flows we have covered here — sequential, conditional and loops/iterative flow.

Going Forward

Now you’ve learned the most basic concepts of programming your computer. If you desire to learn more, or want to make a career out of software development, then all you need to do is dive deeper into the deeper waters. There are so many resources to help you learn. Knowing which to pick up based on your level of experience matters a lot.

Try not to get overwhelmed by the new words you hear from the more experienced programmers in your circle of friends. You could keep a pad to note down these terms, but do not be under pressure to find out what they mean. You will catch up as you learn and practice.

Here are a few resources to help jump-start your coding career, and to help build on the foundation you got from here:

  • //www.codecademy.com/

    Pick the Python course

  • //app.pluralsight.com/library/courses/what-is-programming/table-of-contents

    Free Course on Pluralsight

NOTE: I don’t recommend over-reading on the same topic. I believe in acting on the little you’ve learned, that is, practicing. This is why I’m not dumping too many links here for your learning. Feel free to google up or find others based on what you already know if you are not a first-timer.

Final Challenge

I hereby challenge you to:

Take up any of these challenges:

  • Find any simple app online and reproduce it in the programming language you have learned

OR

  • Think of any idea even if it’s as simple as a bucket list app

    build an app around this idea.

Jeg vil anbefale denne artikel fra codementor for at komme i gang med dette.

Svar på quizzen

Identificer kodningsstrømmene i de følgende Python-kodestykker.

  • Sekventiel strømning
  • Iteration

    den whileopgørelse

  • Betinget

    den ifopgørelse

Særlig tak til Maya Neria, Joshua Ugba og Mohini Ufeli for at have gennemgået denne opskrivning, Surajudeen Akande for at opfordre mig til at offentliggøre det, redaktionsteamet i Andela for anmeldelserne, John Adesanya for illustrationer og til 'Kunmi - disse lektioner startede med hendes ønske om at lære at kode.

Hvis du kunne lide dette, skal du klikke på klapp-ikonet, så andre mennesker kan se dette her på medium. Brug også kommentarsektionen til at dele dine tanker, hvis du har spørgsmål eller bemærkninger.