(function(){var b=document.getElementById(“rhyt-smPYRJbj9zE”);if(!b)return;b.addEventListener(“click”,function(){var f=document.createElement(“iframe”);f.src=”https://www.youtube-nocookie.com/embed/”+b.dataset.id+”?autoplay=1″;f.title=b.getAttribute(“aria-label”);f.setAttribute(“allow”,”accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture”);f.setAttribute(“allowfullscreen”,””);f.style.cssText=”position:absolute;inset:0;width:100%;height:100%;border:0″;b.replaceWith(f);});})();
{“@context”:”https://schema.org”,”@type”:”VideoObject”,”name”:”Programming Concepts | IGCSE Computer Science 0478 Paper 2 Full Lesson (Pseudocode Explained)”,”description”:”The full lesson on Cambridge IGCSE Computer Science 0478 Unit 8 Programming for Paper 2: variables and constants, data types, operators, selection (IF and CASE), iteration (FOR, WHILE, REPEAT), string handling and more, with pseudocode explained.”,”thumbnailUrl”:”https://i.ytimg.com/vi/smPYRJbj9zE/hqdefault.jpg”,”uploadDate”:”2026-11-27″,”duration”:”PT10M18S”,”embedUrl”:”https://www.youtube-nocookie.com/embed/smPYRJbj9zE”,”contentUrl”:”https://www.youtube.com/watch?v=smPYRJbj9zE”,”publisher”:{“@type”:”Organization”,”name”:”Revision Hub”,”url”:”https://revisionhub.online/”}}
A variable is a named memory location whose value can change while the program runs. A constant is a named value that cannot change, which makes programs easier to update and read.
Use OUTPUT to display values and prompts, and INPUT to read a value from the user into a variable.
OUTPUT "Enter your age"
INPUT Age
OUTPUT "In 5 years you will be ", Age + 5
4. Sequence and selection
Sequence means statements run one after another in order. Selection chooses which statements run, using IF or CASE. The example below also shows nested selection: an IF inside another IF.
IF Temperature > 30
THEN
OUTPUT "Hot"
ELSE
IF Temperature > 15
THEN
OUTPUT "Warm"
ELSE
OUTPUT "Cold"
ENDIF
ENDIF
CASE OF Choice
1 : OUTPUT "Play"
2 : OUTPUT "Settings"
3 : OUTPUT "Quit"
OTHERWISE OUTPUT "Invalid choice"
ENDCASE
5. Iteration
Loop
Pseudocode
When to use it
Count-controlled
FOR … TO … NEXT
When you know how many times to repeat
Pre-condition
WHILE … DO … ENDWHILE
When the condition is checked before each repeat; it may run zero times
Post-condition
REPEAT … UNTIL
When the code must run at least once, e.g. validating input
Totalling (Total ← Total + Value) and counting (Count ← Count + 1) are done inside loops; see Unit 7 for full examples.
In Cambridge pseudocode the first character is at position 1. Some programming languages start at 0.
7. Operators
Type
Operators
Arithmetic
+ − * / ^ (power), MOD (remainder), DIV (whole-number division)
Relational
= < <= > >= <> (not equal to)
Logical
AND, OR, NOT
8. Procedures, functions and parameters
A procedure is a named block of code that performs a task; it is run with CALL. A function is similar but always returns a value, so it is used inside an expression. Parameters pass values into them (up to three in the exam).
PROCEDURE ShowLine(Size : INTEGER)
FOR Count ← 1 TO Size
OUTPUT "-"
NEXT Count
ENDPROCEDURE
FUNCTION Area(Length : REAL, Width : REAL) RETURNS REAL
RETURN Length * Width
ENDFUNCTION
CALL ShowLine(10)
OUTPUT Area(4.5, 2)
A local variable exists only inside the procedure or function where it is declared. A global variable can be used anywhere in the program.
9. Library routines
OUTPUT MOD(17, 5) // 2: the remainder
OUTPUT DIV(17, 5) // 3: whole-number division
OUTPUT ROUND(3.14159, 2) // 3.14
Dice ← ROUND(RANDOM() * 5, 0) + 1 // a whole number from 1 to 6
10. Maintainable programs
Meaningful identifiers for variables, constants, arrays, procedures and functions, e.g. TotalScore, not T.
Comments (// in pseudocode) that explain what sections of code do.
Procedures and functions that break the program into reusable parts.
11. Arrays
An array stores many values of the same data type under one name. Each value is accessed by its index, which can be a variable. A 1D array is a list; a 2D array is a table of rows and columns. Use loops (and nested loops for 2D) to read and write values.
DECLARE Marks : ARRAY[1:5] OF INTEGER
FOR Index ← 1 TO 5
INPUT Marks[Index]
NEXT Index
DECLARE Board : ARRAY[1:3, 1:3] OF CHAR
FOR Row ← 1 TO 3
FOR Column ← 1 TO 3
Board[Row, Column] ← '-'
NEXT Column
NEXT Row
12. File handling
Data stored in a file is kept after the program ends, so it can be used again later or by another program.
Pick an example or write your own Cambridge-style pseudocode, add any inputs, and press Run. Supports DECLARE, CONSTANT, ←, INPUT, OUTPUT, IF, CASE, FOR, WHILE, REPEAT, arrays, procedures, functions and the library routines.
#rh-run select{font:inherit;font-size:15px;border:1px solid #D6DCE7;border-radius:10px;padding:8px 12px}#rh-run .rn-code{width:100%;box-sizing:border-box;background:#12203F;color:#E6F7F8;border:0;border-radius:12px;padding:14px 16px;font:14px/1.6 monospace;tab-size:2}#rh-run .rn-in{width:100%;box-sizing:border-box;font-family:monospace}#rh-run .rn-go{background:#0B7C86;color:#fff;border-color:#0B7C86}#rh-run .rn-out{background:#F4F7FB;border-radius:10px;padding:12px 16px;font:14px/1.6 monospace;white-space:pre-wrap;min-height:80px;margin:0}
(function(){
var w=document.getElementById(‘rh-run’);if(!w)return;
var box=w.querySelector(‘.rn-box’);
box.innerHTML=’‘;
var EX={
‘Grade (IF and CASE)’:’// Give a grade for a mark\nDECLARE Mark : INTEGER\nINPUT Mark\nIF Mark >= 50\n THEN\n OUTPUT “Pass”\n ELSE\n OUTPUT “Fail”\nENDIF\nCASE OF DIV(Mark, 10)\n 10 : OUTPUT “Grade A*”\n 9 : OUTPUT “Grade A*”\n 8 : OUTPUT “Grade A”\n 7 : OUTPUT “Grade B”\n 6 : OUTPUT “Grade C”\n OTHERWISE OUTPUT “Keep practising”\nENDCASE’,
‘Times table (FOR loop)’:’// Output a times table\nINPUT Number\nFOR Count ← 1 TO 10\n OUTPUT Number, ” x “, Count, ” = “, Number * Count\nNEXT Count’,
‘Total and average (WHILE)’:’// Input marks until -1 is entered\nTotal ← 0\nCount ← 0\nINPUT Mark\nWHILE Mark -1 DO\n Total ← Total + Mark\n Count ← Count + 1\n INPUT Mark\nENDWHILE\nIF Count > 0\n THEN\n OUTPUT “Average: “, ROUND(Total / Count, 1)\nENDIF’,
‘String handling’:’// Work with a name\nINPUT Name\nOUTPUT “Length: “, LENGTH(Name)\nOUTPUT “Upper: “, UCASE(Name)\nOUTPUT “Lower: “, LCASE(Name)\nOUTPUT “First 3 letters: “, SUBSTRING(Name, 1, 3)’,
‘Array and linear search’:’DECLARE Names : ARRAY[1:5] OF STRING\nFOR Index ← 1 TO 5\n INPUT Names[Index]\nNEXT Index\nINPUT SearchName\nFound ← FALSE\nIndex ← 1\nREPEAT\n IF Names[Index] = SearchName\n THEN\n Found ← TRUE\n ELSE\n Index ← Index + 1\n ENDIF\nUNTIL Found = TRUE OR Index > 5\nIF Found\n THEN\n OUTPUT SearchName, ” is at position “, Index\n ELSE\n OUTPUT SearchName, ” not found”\nENDIF’,
‘Procedure and function’:’FUNCTION Square(Number : INTEGER) RETURNS INTEGER\n RETURN Number * Number\nENDFUNCTION\n\nPROCEDURE Stars(Size : INTEGER)\n Line ← “”\n FOR I ← 1 TO Size\n Line ← Line + “*”\n NEXT I\n OUTPUT Line\nENDPROCEDURE\n\nINPUT N\nOUTPUT N, ” squared is “, Square(N)\nCALL Stars(N)’
};
var INS={‘Grade (IF and CASE)’:’73’,’Times table (FOR loop)’:’7′,’Total and average (WHILE)’:’60, 72, 85, -1′,’String handling’:’Amelia’,’Array and linear search’:’Ali, Bea, Can, Deniz, Ela, Can’,’Procedure and function’:’5′};
var sel=w.querySelector(‘.rn-ex’),code=w.querySelector(‘.rn-code’),inp=w.querySelector(‘.rn-in’),out=w.querySelector(‘.rn-out’);
Object.keys(EX).forEach(function(k){var o=document.createElement(‘option’);o.textContent=k;sel.appendChild(o);});
function load(){code.value=EX[sel.value];inp.value=INS[sel.value];out.textContent=’Press Run to execute the pseudocode.’;}
sel.onchange=load;
function Err(m,l){this.m=m;this.l=l;}
function Ret(v){this.v=v;}
var TOK=/\s*(?:(\d+\.\d+|\d+)|(“[^”]*”|'[^’]*’|‘[^’]*’)|(|=|<-|←|[-+*\/^=()\[\],:&])|([A-Za-z_][A-Za-z0-9_]*))/y;
function lex(s,ln){var t=[],m;TOK.lastIndex=0;s=s.replace(/\s+$/,”);while(TOK.lastIndex<s.length){var st=TOK.lastIndex;m=TOK.exec(s);if(!m){throw new Err('Cannot read: '+s.slice(st).trim(),ln);}if(m[1]!==undefined)t.push({k:'n',v:+m[1]});else if(m[2]!==undefined)t.push({k:'s',v:m[2].slice(1,-1)});else if(m[3]!==undefined)t.push({k:'o',v:m[3]==='<-'?'←':m[3]});else t.push({k:'i',v:m[4]});}return t;}
function P(toks,ln){this.t=toks;this.p=0;this.ln=ln;}
P.prototype.peek=function(){return this.t[this.p];};
P.prototype.is=function(v){var x=this.t[this.p];if(!x)return false;if(x.k==='o')return x.v===v;if(x.k==='i')return x.v.toUpperCase()===v;return false;};
P.prototype.eat=function(v){if(!this.is(v))throw new Err('Expected '+v,this.ln);this.p+=1;};
P.prototype.expr=function(){var l=this.and();while(this.is('OR')){this.p+=1;l={k:'or',a:l,b:this.and()};}return l;};
P.prototype.and=function(){var l=this.not();while(this.is('AND')){this.p+=1;l={k:'and',a:l,b:this.not()};}return l;};
P.prototype.not=function(){if(this.is('NOT')){this.p+=1;return {k:'not',a:this.not()};}return this.rel();};
P.prototype.rel=function(){var l=this.add();var ops=['=','’,'<','’,’>=’];for(var i=0;i<ops.length;i++){if(this.is(ops[i])){this.p+=1;return {k:'bin',o:ops[i],a:l,b:this.add()};}}return l;};
P.prototype.add=function(){var l=this.mul();while(this.is('+')||this.is('-')||this.is('&')){var o=this.peek().v;this.p+=1;l={k:'bin',o:o,a:l,b:this.mul()};}return l;};
P.prototype.mul=function(){var l=this.pow();while(this.is('*')||this.is('/')||this.is('MOD')||this.is('DIV')){var x=this.peek();var o=x.k==='o'?x.v:x.v.toUpperCase();this.p+=1;l={k:'bin',o:o,a:l,b:this.pow()};}return l;};
P.prototype.pow=function(){var l=this.un();if(this.is('^')){this.p+=1;return {k:'bin',o:'^',a:l,b:this.pow()};}return l;};
P.prototype.un=function(){if(this.is('-')){this.p+=1;return {k:'neg',a:this.un()};}return this.prim();};
P.prototype.prim=function(){var x=this.peek();if(!x)throw new Err('Expression is incomplete',this.ln);
if(x.k==='n'){this.p+=1;return {k:'lit',v:x.v};}
if(x.k==='s'){this.p+=1;return {k:'lit',v:x.v};}
if(this.is('(')){this.p+=1;var e=this.expr();this.eat(')');return e;}
if(x.k==='i'){var u=x.v.toUpperCase();this.p+=1;if(u==='TRUE')return {k:'lit',v:true};if(u==='FALSE')return {k:'lit',v:false};
if(this.is('(')){this.p+=1;var args=[];if(!this.is(')')){args.push(this.expr());while(this.is(',')){this.p+=1;args.push(this.expr());}}this.eat(')');return {k:'call',n:x.v,a:args};}
if(this.is('[')){this.p+=1;var ix=[this.expr()];while(this.is(',')){this.p+=1;ix.push(this.expr());}this.eat(']');return {k:'idx',n:x.v,i:ix};}
return {k:'var',n:x.v};}
throw new Err('Unexpected '+x.v,this.ln);};
function pexpr(s,ln){var p=new P(lex(s,ln),ln);var e=p.expr();if(p.p<p.t.length)throw new Err('Unexpected '+p.t[p.p].v,ln);return e;}
function plist(s,ln){var p=new P(lex(s,ln),ln);var a=[p.expr()];while(p.is(',')){p.p+=1;a.push(p.expr());}if(p.p<p.t.length)throw new Err('Unexpected '+p.t[p.p].v,ln);return a;}
function ptarget(s,ln){var p=new P(lex(s,ln),ln);var e=p.prim();if(e.k!=='var'){if(e.k!=='idx')throw new Err('Cannot assign to this',ln);}if(p.p<p.t.length)throw new Err('Unexpected '+p.t[p.p].v,ln);return e;}
function strip(l){var q=null,r='';for(var i=0;i0;});var pos=0,funcs={};
function up(s){return s.toUpperCase();}
function startsW(s,w){var u=up(s);if(u===w)return true;return u.indexOf(w+’ ‘)===0;}
function block(ends){var out=[];while(pos<L.length){var ln=L[pos],u=up(ln.s);for(var e=0;e<ends.length;e++){if(u===ends[e]||u.indexOf(ends[e]+' ')===0)return out;}out.push(stmt());}if(ends.length)throw new Err('Missing '+ends.join(' or '),L.length?L[L.length-1].n:1);return out;}
function stmt(){var ln=L[pos],s=ln.s,u=up(s),n=ln.n,m;pos+=1;
if(startsW(s,'DECLARE')){m=s.match(/^DECLARE\s+(\w+)\s*:\s*ARRAY\s*\[\s*(.+?)\s*\]\s*OF\s+\w+$/i);if(m){var dims=m[2].split(',').map(function(d){var r=d.split(':');if(r.length!==2)throw new Err('Array bounds should look like [1:10]',n);return [pexpr(r[0],n),pexpr(r[1],n)];});return {t:'arr',n:m[1],d:dims,ln:n};}if(/^DECLARE\s+\w+\s*:\s*\w+$/i.test(s))return {t:'nop'};throw new Err('DECLARE should look like: DECLARE Name : INTEGER',n);}
if(startsW(s,'CONSTANT')){m=s.match(/^CONSTANT\s+(\w+)\s*(?:←|<-|=)\s*(.+)$/i);if(!m)throw new Err('CONSTANT should look like: CONSTANT Rate ← 6.5',n);return {t:'set',g:{k:'var',n:m[1]},e:pexpr(m[2],n),ln:n};}
if(startsW(s,'INPUT')){return {t:'in',g:ptarget(s.slice(5),n),ln:n};}
if(startsW(s,'OUTPUT')||startsW(s,'PRINT')){return {t:'out',e:plist(s.replace(/^\w+/,''),n),ln:n};}
if(startsW(s,'IF')){var c=s.slice(2).replace(/\s+THEN\s*$/i,'');var st={t:'if',c:pexpr(c,n),y:[],no:[],ln:n};if(pos<L.length){if(up(L[pos].s)==='THEN')pos+=1;}st.y=block(['ELSE','ENDIF']);if(up(L[pos].s)==='ELSE'){pos+=1;st.no=block(['ENDIF']);}pos+=1;return st;}
if(startsW(s,'CASE')){m=s.match(/^CASE\s+OF\s+(.+)$/i);if(!m)throw new Err('CASE should look like: CASE OF Choice',n);var cs={t:'case',e:pexpr(m[1],n),c:[],o:null,ln:n};while(pos<L.length){var l2=L[pos];if(up(l2.s)==='ENDCASE'){pos+=1;return cs;}if(startsW(l2.s,'OTHERWISE')){var rest=l2.s.replace(/^OTHERWISE\s*:?\s*/i,'');pos+=1;var sv=pos;L.splice(pos,0,{s:rest,n:l2.n});cs.o=[stmt()];continue;}var ci=l2.s.indexOf(' : ');if(ci<0)ci=l2.s.indexOf(':');if(ci<0)throw new Err('Each case should look like: value : statement',l2.n);var vals=plist(l2.s.slice(0,ci),l2.n);var body=l2.s.slice(ci+1).replace(/^\s*:?\s*/,'');pos+=1;L.splice(pos,0,{s:body,n:l2.n});cs.c.push({v:vals,b:[stmt()]});}throw new Err('Missing ENDCASE',n);}
if(startsW(s,'FOR')){m=s.match(/^FOR\s+(\w+)\s*(?:←|0;});var fb=block([isF?’ENDFUNCTION’:’ENDPROCEDURE’]);pos+=1;funcs[up(m[1])]={p:ps,b:fb,f:isF,n:m[1]};return {t:’nop’};}
if(startsW(s,’CALL’)){var ce=pexpr(s.slice(4),n);if(ce.k===’var’)ce={k:’call’,n:ce.n,a:[]};return {t:’call’,e:ce,ln:n};}
if(startsW(s,’RETURN’)){return {t:’ret’,e:pexpr(s.slice(6),n),ln:n};}
var ai=s.search(/←|0){var op=s[ai]===’0;}),qi=0,prog;
try{prog=parse(src);}catch(e){out.textContent=e instanceof Err?’Syntax error on line ‘+e.l+’: ‘+e.m:’Error: ‘+e.message;return;}
var G={},arrs={},F=prog.f;
function look(sc,n){var u=n.toUpperCase();for(var i=sc.length-1;i>=0;i-=1){if(u in sc[i])return sc[i];}return null;}
function get(sc,n,ln){var s=look(sc,n);if(!s)throw new Err(n+’ has no value yet’,ln);return s[n.toUpperCase()];}
function put(sc,n,v){var s=look(sc,n);if(!s)s=sc[sc.length-1];s[n.toUpperCase()]=v;}
function key(sc,node,ln){var a=look(sc,node.n);var A=a?a[node.n.toUpperCase()]:null;if(!A){throw new Err(node.n+’ is not a declared array’,ln);}if(!A.arr)throw new Err(node.n+’ is not a declared array’,ln);var ks=node.i.map(function(e,d){var v=ev(sc,e,ln);var lo=A.d[d][0],hi=A.d[d][1];if(vhi)throw new Err(‘Index ‘+v+’ is outside ‘+node.n+'[‘+lo+’:’+hi+’]’,ln);return v;});return {A:A,k:ks.join(‘,’)};}
function tru(v){return v===true;}
function ev(sc,e,ln){steps+=1;if(steps>200000)throw new Err(‘Too many steps: is there an infinite loop?’,ln);
switch(e.k){case ‘lit’:return e.v;case ‘var’:return get(sc,e.n,ln);
case ‘idx’:var r=key(sc,e,ln);if(!(r.k in r.A.v))throw new Err(e.n+'[‘+r.k+’] has no value yet’,ln);return r.A.v[r.k];
case ‘neg’:return -ev(sc,e.a,ln);
case ‘not’:return !tru(ev(sc,e.a,ln));
case ‘and’:if(!tru(ev(sc,e.a,ln)))return false;return tru(ev(sc,e.b,ln));
case ‘or’:if(tru(ev(sc,e.a,ln)))return true;return tru(ev(sc,e.b,ln));
case ‘bin’:var a=ev(sc,e.a,ln),b=ev(sc,e.b,ln);switch(e.o){case ‘+’:return a+b;case ‘&’:return String(a)+String(b);case ‘-‘:return a-b;case ‘*’:return a*b;case ‘/’:if(b===0)throw new Err(‘Division by zero’,ln);return a/b;case ‘^’:return Math.pow(a,b);case ‘MOD’:return a%b;case ‘DIV’:return Math.trunc(a/b);case ‘=’:return a===b;case ”:return a!==b;case ‘<':return a<b;case '<=':return a’:return a>b;case ‘>=’:return a>=b;}break;
case ‘call’:var u=e.n.toUpperCase(),A=e.a.map(function(x){return ev(sc,x,ln);});
switch(u){case ‘LENGTH’:return String(A[0]).length;case ‘UCASE’:return String(A[0]).toUpperCase();case ‘LCASE’:return String(A[0]).toLowerCase();case ‘SUBSTRING’:return String(A[0]).substr(A[1]-1,A[2]);case ‘ROUND’:var f=Math.pow(10,A[1]||0);return Math.round(A[0]*f)/f;case ‘RANDOM’:return Math.random();case ‘DIV’:return Math.trunc(A[0]/A[1]);case ‘MOD’:return A[0]%A[1];case ‘INT’:return Math.trunc(A[0]);}
var fn=F[u];if(!fn)throw new Err(‘Unknown function ‘+e.n,ln);if(!fn.f)throw new Err(e.n+’ is a procedure: use CALL’,ln);return callF(sc,fn,A,ln);}
throw new Err(‘Cannot evaluate’,ln);}
function callF(sc,fn,A,ln){if(A.length!==fn.p.length)throw new Err(fn.n+’ needs ‘+fn.p.length+’ parameter(s)’,ln);var loc={};fn.p.forEach(function(p,i){loc[p.toUpperCase()]=A[i];});var ns=[sc[0],loc];try{exec(ns,fn.b);}catch(x){if(x instanceof Ret)return x.v;throw x;}if(fn.f)throw new Err(fn.n+’ finished without RETURN’,ln);return null;}
function show(v){if(v===true)return ‘TRUE’;if(v===false)return ‘FALSE’;if(typeof v===’number’){return String(Math.round(v*1e10)/1e10);}return String(v);}
function exec(sc,body){for(var i=0;i200000)throw new Err(‘Too many steps: is there an infinite loop?’,s.ln);
switch(s.t){case ‘nop’:break;
case ‘arr’:var d=s.d.map(function(b){return [ev(sc,b[0],s.ln),ev(sc,b[1],s.ln)];});put(sc,s.n,{arr:true,d:d,v:{}});break;
case ‘set’:var v=ev(sc,s.e,s.ln);if(s.g.k===’idx’){var r=key(sc,s.g,s.ln);r.A.v[r.k]=v;}else put(sc,s.g.n,v);break;
case ‘in’:if(qi>=queue.length)throw new Err(‘INPUT needs another value: add it to the inputs box’,s.ln);var raw=queue[qi];qi+=1;var val=/^-?\d+(\.\d+)?$/.test(raw)?+raw:(/^true$/i.test(raw)?true:(/^false$/i.test(raw)?false:raw));lines.push(‘? ‘+raw);if(s.g.k===’idx’){var r2=key(sc,s.g,s.ln);r2.A.v[r2.k]=val;}else put(sc,s.g.n,val);break;
case ‘out’:lines.push(s.e.map(function(x){return show(ev(sc,x,s.ln));}).join(”));break;
case ‘if’:exec(sc,tru(ev(sc,s.c,s.ln))?s.y:s.no);break;
case ‘case’:var cv=ev(sc,s.e,s.ln),hit=false;for(var c=0;c<s.c.length;c++){for(var k=0;k0?x=b;x+=st){put(sc,s.v,x);exec(sc,s.body);}break;
case ‘while’:while(tru(ev(sc,s.c,s.ln)))exec(sc,s.body);break;
case ‘rep’:do{exec(sc,s.body);}while(!tru(ev(sc,s.c,s.ln)));break;
case ‘call’:var fn=F[s.e.n.toUpperCase()];if(!fn)throw new Err(‘Unknown procedure ‘+s.e.n,s.ln);callF(sc,fn,s.e.a.map(function(y){return ev(sc,y,s.ln);}),s.ln);break;
case ‘ret’:throw new Ret(ev(sc,s.e,s.ln));}}}
try{exec([G],prog.p);lines.push(‘— Program finished —’);}catch(e){if(e instanceof Err)lines.push(‘✗ Error on line ‘+e.l+’: ‘+e.m);else if(e instanceof Ret)lines.push(‘✗ RETURN used outside a function’);else lines.push(‘✗ Error: ‘+e.message);}
out.textContent=lines.join(‘\n’);}
w.querySelector(‘.rn-go’).onclick=run;load();
})();
14. Examiner tips
Write pseudocode, not program code, except in the 15-mark scenario question.
Use meaningful names and comment your code in longer answers.
Functions RETURN a value; procedures don’t. Call a procedure with CALL.
Initialise totals and counters before the loop, and update them inside it.
Close every structure (ENDIF, ENDCASE, NEXT, ENDWHILE, UNTIL, ENDPROCEDURE, ENDFUNCTION).
MOD gives the remainder; DIV gives the whole-number part.
Arrays: check the index range and use a loop to process every element.
Files: OPENFILE before reading or writing, and CLOSEFILE afterwards.
9. Write a function called Average that takes three integer parameters and returns their average. [4]
Show mark guide
FUNCTION Average(A : INTEGER, B : INTEGER, C : INTEGER) RETURNS REAL [1 header with parameters, 1 RETURNS type] · RETURN (A + B + C) / 3 [1] · ENDFUNCTION [1].
10. Explain the difference between a local and a global variable. [2]
Show mark guide
A local variable is declared inside a procedure or function and can only be used there [1]; a global variable is declared in the main program and can be used anywhere in the program [1].
(function(){var w=document.getElementById(‘rh-practice’);if(!w)return;function chk(id,btn){var i=document.getElementById(id),f=btn.parentNode.querySelector(‘.fb’);var got=(i.value||”).replace(/[^a-z0-9]/gi,”).toUpperCase();var ok=i.getAttribute(‘data-a’).split(‘|’).indexOf(got)>-1;f.className=’fb ‘+(ok?’ok’:’no’);f.textContent=got?(ok?’✓ Correct’:’✗ Not quite, try again or show the answer’):’Type an answer first’;}w.addEventListener(‘click’,function(e){var id=e.target.getAttribute(‘data-check’);if(id)chk(id,e.target);});w.addEventListener(‘keydown’,function(e){if(e.key===’Enter’&&e.target.matches(‘input[data-a]’)){e.preventDefault();chk(e.target.id,w.querySelector(‘[data-check=’+e.target.id+’]’));}});})();
16. Topic test: predict your grade
Topic test: predict your grade
15 questions, about 10 minutes. Answer them all, then press Mark my test.
<fieldset class="rh-tq" data-c="1" data-e=" in pseudocode”>
‘+(pc>=75?’Excellent. This topic is exam-ready; keep it fresh with past papers.’:pc>=55?’Good base. Re-read the sections for the questions marked in red, then try again.’:’Work through the notes and the practice questions above, then retake the test.’)+’
Estimated grade for this topic only, based on typical IGCSE grade boundaries. Your real grade depends on both papers.
The three constructs are sequence, selection (IF and CASE) and iteration (FOR, WHILE and REPEAT loops).
What is the difference between a procedure and a function?
A procedure performs a task. A function performs a task and returns a single value that can be used in an expression.
What is the difference between a local and a global variable?
A local variable is declared inside a subroutine and can only be used there. A global variable is declared in the main program and can be used anywhere.
What are the data types in IGCSE Computer Science?
INTEGER, REAL, CHAR, STRING and BOOLEAN.
What is a 2D array?
A 2D array is a table of data items of the same data type, accessed using two indexes: one for the row and one for the column, for example Marks[2, 3].
What string handling operations do I need for IGCSE?
Finding the length of a string, extracting a substring, and converting to upper case or lower case.
Why do programmers use procedures and functions?
They let a block of code be written once and reused, make programs easier to read, test and maintain, and allow a large task to be split between programmers.
{“@context”:”https://schema.org”,”@type”:”FAQPage”,”mainEntity”:[{“@type”:”Question”,”name”:”What are the three basic programming constructs?”,”acceptedAnswer”:{“@type”:”Answer”,”text”:”The three constructs are sequence, selection (IF and CASE) and iteration (FOR, WHILE and REPEAT loops).”}},{“@type”:”Question”,”name”:”What is the difference between a procedure and a function?”,”acceptedAnswer”:{“@type”:”Answer”,”text”:”A procedure performs a task. A function performs a task and returns a single value that can be used in an expression.”}},{“@type”:”Question”,”name”:”What is the difference between a local and a global variable?”,”acceptedAnswer”:{“@type”:”Answer”,”text”:”A local variable is declared inside a subroutine and can only be used there. A global variable is declared in the main program and can be used anywhere.”}},{“@type”:”Question”,”name”:”What are the data types in IGCSE Computer Science?”,”acceptedAnswer”:{“@type”:”Answer”,”text”:”INTEGER, REAL, CHAR, STRING and BOOLEAN.”}},{“@type”:”Question”,”name”:”What is a 2D array?”,”acceptedAnswer”:{“@type”:”Answer”,”text”:”A 2D array is a table of data items of the same data type, accessed using two indexes: one for the row and one for the column, for example Marks[2, 3].”}},{“@type”:”Question”,”name”:”What string handling operations do I need for IGCSE?”,”acceptedAnswer”:{“@type”:”Answer”,”text”:”Finding the length of a string, extracting a substring, and converting to upper case or lower case.”}},{“@type”:”Question”,”name”:”Why do programmers use procedures and functions?”,”acceptedAnswer”:{“@type”:”Answer”,”text”:”They let a block of code be written once and reused, make programs easier to read, test and maintain, and allow a large task to be split between programmers.”}}]}