\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{lcheong} \pdfinfo{ /Title (pseudocode.pdf) /Creator (Cheatography) /Author (lcheong) /Subject (Pseudocode Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{000000} \definecolor{LightBackground}{HTML}{F7F7F7} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{Pseudocode Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{lcheong} via \textcolor{DarkBackground}{\uline{cheatography.com/59690/cs/15631/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}lcheong \\ \uline{cheatography.com/lcheong} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Not Yet Published.\\ Updated 30th April, 2018.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{2} \begin{tabularx}{8.4cm}{x{3.52 cm} x{4.48 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Declaring Variables and Constants}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{nobreak\}\}{\bf{Variables are assigned using the = operator e.g. {\emph{x = 3}}.}}} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \{\{nobreak\}\}{\bf{Local variables}} & \{\{bl\}\}Variables declared inside a function or procedure are local to that subroutine. \tn % Row Count 6 (+ 4) % Row 2 \SetRowColor{LightBackground} \{\{nobreak\}\}{\bf{Global variables}} & \{\{bl\}\}Variables in the main program can be made global with the keyword global. E.g. {\bf{GLOBAL userid = 123.}} \tn % Row Count 11 (+ 5) % Row 3 \SetRowColor{white} \{\{nobreak\}\}{\bf{Constants}} & \{\{bl\}\}The values of constants do not change throughout the program. \{\{nl\}\}E.g. {\bf{CONST Vat = 20.}} \tn % Row Count 16 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{1.224 cm} x{1.584 cm} x{2.808 cm} x{1.584 cm} } \SetRowColor{DarkBackground} \mymulticolumn{4}{x{8.4cm}}{\bf\textcolor{white}{Data Types}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Integer}} & VAR age as INTEGER & Whole numbers only & 0, 6, 10293, -999 \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} {\bf{Real or Float}} & VAR price as REAL & Numbers that have a decimal point & 0.15, -5.87, 100.0 \tn % Row Count 6 (+ 3) % Row 2 \SetRowColor{LightBackground} {\bf{Char}} & VAR letter as CHAR & A single letter, number, symbol & "A", "k", "5", "-", "\$" \tn % Row Count 9 (+ 3) % Row 3 \SetRowColor{white} {\bf{String}} & VAR name as STRING & Used to represent text, it is a collection of characters & \seqsplit{"FsTmQ2"}, \seqsplit{"\$money\$"} \tn % Row Count 13 (+ 4) % Row 4 \SetRowColor{LightBackground} {\bf{Boolean}} & VAR \seqsplit{numFound} as BOOLEAN & Could take one of two values, usually TRUE or FALSE & \seqsplit{True/False}, 1/0, Yes/No \tn % Row Count 17 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}----} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4.32 cm} x{3.68 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Casting Variables}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{{\bf{You can change the data type of a variable by using casting.}}} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} {\bf{Converting integer 3 to string.}} & \{\{bl\}\}str(3) returns "3" \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} {\bf{Converting string "3" to integer.}} & \{\{bl\}\}int("3") returns 3 \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} {\bf{Converting string "3.14" to float.}} & \{\{bl\}\}float("3.14") returns 3.14 \tn % Row Count 8 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{String Handling}} \tn % Row 0 \SetRowColor{LightBackground} \{\{nobreak\}\}{\bf{Finding the length of a string}} & \{\{bl\}\}\{\{nobreak\}\}VAR name as STRING \{\{nl\}\} name = INPUT("Enter your name") \{\{nl\}\} PRINT("Your name has" + name.length + "characters") \tn % Row Count 7 (+ 7) % Row 1 \SetRowColor{white} \{\{nobreak\}\}{\bf{Getting a substring}} & \{\{bl\}\}\{\{nobreak\}\}stringname.subString(startingPosition, numberOfCharacters) \{\{nl\}\}{\bf{NB}} The string will start with the {\bf{0}}th character. \{\{nl\}\} {\bf{Example:}}\{\{nl\}\}someText = "Computer Science" \{\{nl\}\} \seqsplit{PRINT(someText.length)} \{\{nl\}\} \seqsplit{PRINT(someText.substring(3},3)) \{\{nl\}\} {\bf{Will display:}} \{\{nl\}\} 16 \{\{nl\}\} put \tn % Row Count 23 (+ 16) % Row 2 \SetRowColor{LightBackground} {\bf{Extracting a specific chatacter from a string}} & \{\{bl\}\}name{[}i{]} \{\{nl\}\} {\bf{Example:}} \{\{nl\}\} name = "Paloma" \{\{nl\}\} name{[}3{]} returns "o" \tn % Row Count 28 (+ 5) % Row 3 \SetRowColor{white} {\bf{Converting to uppercase}} & \{\{bl\}\}name.UPPER() \tn % Row Count 30 (+ 2) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{String Handling (cont)}} \tn % Row 4 \SetRowColor{LightBackground} {\bf{Converting to lowercase}} & \{\{bl\}\}name.LOWER() \tn % Row Count 2 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{1.84 cm} x{6.16 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Taking inputs from user}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{{\bf{Inputs taken from a user need to be stored in a variable.}}} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} {\bf{Example:}} & VAR name as STRING \{\{nl\}\} name = INPUT("Enter your name") \tn % Row Count 4 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Outputting to screen}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Outputting a string}} & \{\{bl\}\}PRINT("Hello") \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} {\bf{Outputting a variable set by you}} & \{\{bl\}\}word = ("Hello") \{\{nl\}\} PRINT(word) \tn % Row Count 5 (+ 3) % Row 2 \SetRowColor{LightBackground} {\bf{Outputting a variable entered by the user}} & \{\{bl\}\}\{\{nobreak\}\}VAR name as STRING \{\{nl\}\} name = INPUT("What is your name?") \{\{nl\}\} PRINT("Hello" + name) \tn % Row Count 11 (+ 6) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{1-Dimensional Arrays}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Declaring an array}} & \{\{bl\}\}ARRAY names{[}5{]} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} {\bf{Initialising an array - filling it up with values}} & \{\{bl\}\}names{[}0{]} = "Ahmad" \{\{nl\}\} names{[}1{]} = "Ben" \{\{nl\}\} names{[}2{]} = "Catherine" \{\{nl\}\} names{[}3{]} = "Dana" \{\{nl\}\} names{[}4{]} = "Elijah" \tn % Row Count 9 (+ 7) % Row 2 \SetRowColor{LightBackground} {\bf{Displaying a specific item from an array}} & \{\{bl\}\}PRINT(names{[}3{]}) \{\{nl\}\} will display "Dana" \tn % Row Count 12 (+ 3) % Row 3 \SetRowColor{white} {\bf{Displaying ALL items in an array - method 1}} & \{\{bl\}\}FOR i = 0 to 5\{\{nl\}\}~~~PRINT(names{[}i{]})\{\{nl\}\} NEXT i \tn % Row Count 16 (+ 4) % Row 4 \SetRowColor{LightBackground} {\bf{Displaying ALL items in an array - method 2}} & \{\{bl\}\}ARRAY names{[}5{]} \{\{nl\}\}names{[}0{]} = "Ahmad" \{\{nl\}\} names{[}1{]} = "Ben" \{\{nl\}\} names{[}2{]} = "Catherine" \{\{nl\}\} names{[}3{]} = "Dana" \{\{nl\}\} names{[}4{]} = "Elijah"\{\{nl\}\}PRINT(names) \tn % Row Count 25 (+ 9) % Row 5 \SetRowColor{white} {\bf{Dynamically inserting values in an array}} & \{\{bl\}\}{\bf{E.g. Ask the user to enter 5 names}} \{\{nl\}\} FOR i = 0 to 5\{\{nl\}\}~~~names{[}i{]} = INPUT("Enter name:") \{\{nl\}\} NEXT i \tn % Row Count 32 (+ 7) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{1-Dimensional Arrays (cont)}} \tn % Row 6 \SetRowColor{LightBackground} {\bf{Performing calculations on one Array element}} & \{\{bl\}\}{\bf{E.g. Increase element 2 of ARRAY age by 10: }} age{[}2{]} = age{[}2{]} + 10 \tn % Row Count 4 (+ 4) % Row 7 \SetRowColor{white} {\bf{Performing calculations on Array elements}} & \{\{bl\}\}{\bf{E.g. Increase {\emph{ALL}} the values in ARRAY ages by 2: }}\{\{nl\}\} FOR i = 0 to 4 \{\{nl\}\} ~~~ age{[}i{]} = age{[}i{]} + 2 \{\{nl\}\} NEXT i \tn % Row Count 12 (+ 8) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{2-Dimensional Arrays}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Note: }} & {\bf{{\emph{Refer to CGP Page 50}}}} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} {\bf{Declaring a 2D array}} & A 2D array is built as ARRAY(row, column)\{\{nl\}\} ARRAY score{[}4,5{]} \{\{nl\}\} builds an array of 4 rows, 5 columns. \{\{nl\}\} This can be interpreted as 4 Tests, 5 Students \tn % Row Count 11 (+ 9) % Row 2 \SetRowColor{LightBackground} {\bf{Initialising a 2D array - filling it up with values}} & score{[}0,0{]} = "15" \{\{nl\}\} Sets score 15 to Test 0, Student 0 \tn % Row Count 14 (+ 3) % Row 3 \SetRowColor{white} {\bf{Displaying a specific item from a 2D array}} & PRINT(score{[}1,3{]}) \{\{nl\}\} will display 14 \tn % Row Count 17 (+ 3) % Row 4 \SetRowColor{LightBackground} {\bf{Dynamically inserting values in an array}} & \{\{nobreak\}\}{\bf{E.g. Ask the user to enter all the scores }} \{\{nl\}\} FOR i = 0 to 3\{\{nl\}\}~~~ FOR j = 0 to 4 \{\{nl\}\}~~~~~~score{[}i,j{]} = INPUT("Enter score for Test " + i + " Student " + j + ": ") \{\{nl\}\} ~~~~NEXT j \{\{nl\}\}NEXT i \tn % Row Count 32 (+ 15) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Sub Programs - Functions}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{{\bf{Functions take at least one parameter and they must always return a value.}}} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{{\bf{Example: }} Write a function to join two strings together with a space between them and show it working on the strings "computer" and "science".} \tn % Row Count 5 (+ 3) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{FUNCTION join\_strings(x as STRING, y as STRING) as STRING\{\{nl\}\}~~~RETURN x + " " + y\{\{nl\}\}ENDFUNCTION} \tn % Row Count 8 (+ 3) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{{\bf{Calling the function from the main program:}} \{\{nl\}\} subject = join\_strings("computer", "science") \{\{nl\}\}PRINT(subject)} \tn % Row Count 11 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Sub Programs - Procedures}} \tn % Row 0 \SetRowColor{LightBackground} \{\{nobreak\}\}{\bf{Procedures don't have to take parameters...}} \{\{nl\}\} PROCEDURE welcome() \{\{nl\}\}~~~PRINT("Hello and welcome.")\{\{nl\}\}~~~PRINT("Let's learn about procedures.")\{\{nl\}\}ENDPROCEDURE & \{\{bl\}\}\{\{nobreak\}\}{\bf{...but sometimes they will.}} \{\{nl\}\} PROCEDURE betterwelcome(name as STRING) \{\{nl\}\}~~~PRINT("Hello" + name + "and welcome.")\{\{nl\}\}~~~PRINT("Let's learn about procedures.")\{\{nl\}\}ENDPROCEDURE \tn % Row Count 12 (+ 12) % Row 1 \SetRowColor{white} Procedures are called by typing their name... & \{\{bl\}\}...and giving an argument if necessary \tn % Row Count 15 (+ 3) % Row 2 \SetRowColor{LightBackground} welcome() & \{\{bl\}\}betterwelcome("Pablo") \tn % Row Count 17 (+ 2) % Row 3 \SetRowColor{white} {\bf{Will display:}} \{\{nl\}\} Hello and welcome. \{\{nl\}\} Let's Learn about procedures. & \{\{bl\}\}{\bf{Will display:}} \{\{nl\}\} Hello Pablo and welcome. \{\{nl\}\} Let's Learn about procedures. \tn % Row Count 22 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{Note that procedures {\bf{DO NOT}} return a value} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{File Handling - Writing to a file}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{{\bf{Adding a line of text to a file}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{myFile = openWrite("sample.txt") \{\{nl\}\} myFile.writeline("Hello World") \{\{nl\}\} myFile.close()} \tn % Row Count 3 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{File Handling - Reading from a file}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{{\bf{Reading and outputting a single line from the text file}} (see further details in CGP Pg 51)} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{myFile = openRead("sample.txt") \{\{nl\}\} x = myFile.readLine() \{\{nl\}\} myFile.close()} \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{{\bf{Reading and outputting the whole contents of a text file}}} \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{myFile = openRead("sample.txt") \{\{nl\}\} while NOT myFile.endOfFile() \{\{nl\}\}~~~PRINT(myFile.readLine()) \{\{nl\}\}ENDWHILE \{\{nl\}\} myFile.close()} \tn % Row Count 10 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.64 cm} x{5.36 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Comparison operators}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{==}}\{\{br\}\} & Equal to \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} {\bf{!=}}\{\{br\}\} & Not equal to \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} {\bf{\textless{}}}\{\{br\}\} & Less than \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} {\bf{\textless{}=}}\{\{br\}\} & Less than or equal to \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} {\bf{\textgreater{}}}\{\{br\}\} & Greater than \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} {\bf{\textgreater{}=}}\{\{br\}\} & Greater than or equal to \tn % Row Count 6 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{1.2 cm} x{6.8 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Arithmetic operators}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{+}} & Addition \{\{nl\}\}\{\{bl\}\}{\bf{e.g. x=6+5 gives 11}} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} {\bf{-}} & Subtraction \{\{nl\}\}\{\{bl\}\}{\bf{e.g. x=6-5 gives 1}} \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} {\bf{*}} & Multiplication \{\{nl\}\}\{\{bl\}\}{\bf{e.g. x=12*2 gives 24}} \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} {\bf{/}} & Division \{\{nl\}\}\{\{bl\}\}{\bf{e.g. x=12/2 gives 6}} \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} {\bf{MOD}} & Modulus \{\{nl\}\}\{\{bl\}\}{\bf{e.g. 12MOD5 gives 2}} \tn % Row Count 10 (+ 2) % Row 5 \SetRowColor{white} {\bf{DIV}} & Quotient \{\{nl\}\}\{\{bl\}\}{\bf{e.g. 17DIV5 gives 3}} \tn % Row Count 12 (+ 2) % Row 6 \SetRowColor{LightBackground} {\bf{\textasciicircum{}}} & Exponentiation \{\{nl\}\}\{\{bl\}\}{\bf{e.g. 3\textasciicircum{}4 gives 81}} \tn % Row Count 14 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{1.2 cm} x{6.8 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Boolean operators}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{AND}} & \{\{bl\}\}If two or more statements are true. \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} {\bf{OR}} & \{\{bl\}\}If either statement is true. \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} {\bf{NOT}} & \{\{bl\}\}To reverse the logical results of a statement. \tn % Row Count 5 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Selection - if/else}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Selection involves making decisions based on a comparison. {\bf{Comparison operators}} are used, sometimes with {\bf{boolean operators}}.} \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{IF entry == "A" THEN\{\{nl\}\}~~~PRINT("You selected A") \{\{nl\}\}ELSEIF entry == "B" THEN \{\{nl\}\}~~~PRINT("You selected B")\{\{nl\}\}ELSE: \{\{nl\}\}~~~PRINT("Unrecognised selection") \{\{nl\}\}ENDIF} \tn % Row Count 8 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Selection - switch/case}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Selection involves making decisions based on a comparison. {\bf{Comparison operators}} are used, sometimes with {\bf{boolean operators}}.} \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{SWITCH entry:\{\{nl\}\}~~~CASE "A": \{\{nl\}\}~~~~~~PRINT("You selected A")\{\{nl\}\}~~~CASE "B": \{\{nl\}\}~~~~~~PRINT("You selected B")\{\{nl\}\}~~~DEFAULT: \{\{nl\}\}~~~~~~PRINT("Unrecognised selection") \{\{nl\}\}ENDSWITCH} \tn % Row Count 10 (+ 7) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Iteration - For Loop}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{{\bf{FOR loops}} will repeat the code inside them a fixed number of times. The number of times that the code repeats will depend on an {\bf{initial value}}, {\bf{end value}}, and the {\bf{step count}}.} \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{{\bf{Example: }} \{\{nl\}\} FOR i = 0 to 7 \{\{nl\}\}~~~PRINT("Hello") \{\{nl\}\}NEXT i \{\{nl\}\} Will print hello 8 times (0-7 inclusive).} \tn % Row Count 7 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Iteration - Repeat Loop}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{This loop is controlled by a condition at the {\bf{end of the loop}}. Keep going {\bf{until}} the condition is {\bf{TRUE}} (i.e. while it is false). Always runs the code inside it {\bf{at least once}}. You get an {\bf{infinite loop}} if the condition is {\bf{never true}}.} \tn % Row Count 6 (+ 6) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{{\bf{Example:}} Write an algorithm that a supermarket self-scan machine could use to check if enough money has been fed into it and output the right amount of change.} \tn % Row Count 10 (+ 4) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{VAR total as INTEGER \{\{nl\}\} total = 0 \{\{nl\}\} VAR cost, coin, change as INTEGER \{\{nl\}\} cost = total cost in pence \{\{nl\}\} REPEAT \{\{nl\}\} ~~~coin = INPUT("Value of coin") \{\{nl\}\} ~~~total = total + coin \{\{nl\}\} UNTIL total \textgreater{}= cost \{\{nl\}\} change = total - cost \{\{nl\}\} OUTPUT change} \tn % Row Count 17 (+ 7) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Iteration - While Loop}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{This loop is controlled by a condition at the {\bf{start of the loop}}. Keep going {\bf{while}} the condition is {\bf{TRUE}} (i.e. until it is false). Never runs the code inside if condition is initially {\bf{false}}. You get an {\bf{infinite loop}} if the condition is {\bf{always true}}.} \tn % Row Count 6 (+ 6) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{{\bf{Example:}} Write an algorithm that a supermarket self-scan machine could use to check if enough money has been fed into it and output the right amount of change.} \tn % Row Count 10 (+ 4) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{VAR total as INTEGER \{\{nl\}\} total = 0 \{\{nl\}\} VAR cost, coin, change as INTEGER \{\{nl\}\} cost = total cost in pence \{\{nl\}\} WHILE total \textless{} cost \{\{nl\}\} ~~~coin = INPUT("Value of coin") \{\{nl\}\} ~~~total = total + coin \{\{nl\}\} ENDWHILE \{\{nl\}\} change = total - cost \{\{nl\}\} OUTPUT change} \tn % Row Count 17 (+ 7) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Iteration - Do While Loop}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{This loop is controlled by a condition at the {\bf{end of the loop}}. Keep going {\bf{while}} the condition is {\bf{TRUE}} (i.e. until it is false). Always runs the code inside it {\bf{at least once}}. You get an {\bf{infinite loop}} if the condition is {\bf{always true}}.} \tn % Row Count 6 (+ 6) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{{\bf{Example:}} Write an algorithm that a supermarket self-scan machine could use to check if enough money has been fed into it and output the right amount of change.} \tn % Row Count 10 (+ 4) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{VAR total as INTEGER \{\{nl\}\} total = 0 \{\{nl\}\} VAR cost, coin, change as INTEGER \{\{nl\}\} cost = total cost in pence \{\{nl\}\} DO \{\{nl\}\} ~~~coin = INPUT("Value of coin") \{\{nl\}\} ~~~total = total + coin \{\{nl\}\} WHILE total \textless{} cost \{\{nl\}\} OUTPUT change} \tn % Row Count 16 (+ 6) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}