6.S050
Created: 2023-05-11 Thu 11:06
Lectures: TR 1-2:30 in 56-154
No recitations.
Office hours: TBD. Will be on course website & canvas.
"Null references: the billion dollar mistake" — Tony Hoare
IDENTIFICATION DIVISION.
PROGRAM-ID. fizzbuzz.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 CNT PIC 9(03) VALUE 1.
01 REM PIC 9(03) VALUE 0.
01 QUOTIENT PIC 9(03) VALUE 0.
PROCEDURE DIVISION.
*
PERFORM UNTIL CNT > 100
DIVIDE 15 INTO CNT GIVING QUOTIENT REMAINDER REM
IF REM = 0
THEN
DISPLAY "FizzBuzz " WITH NO ADVANCING
ELSE
DIVIDE 3 INTO CNT GIVING QUOTIENT REMAINDER REM
IF REM = 0
THEN
DISPLAY "Fizz " WITH NO ADVANCING
ELSE
DIVIDE 5 INTO CNT GIVING QUOTIENT REMAINDER REM
IF REM = 0
THEN
DISPLAY "Buzz " WITH NO ADVANCING
ELSE
DISPLAY CNT " " WITH NO ADVANCING
END-IF
END-IF
END-IF
ADD 1 TO CNT
END-PERFORM
DISPLAY ""
STOP RUN.
let () =
for i = 1 to 100 do
let str = match i mod 3, i mod 5 with
| 0, 0 -> "FizzBuzz"
| 0, _ -> "Fizz"
| _, 0 -> "Buzz"
| _ -> string_of_int i
in
Printf.printf "%s " str
done
var funcs = [];
// let's create 3 functions
for (var i = 0; i < 3; i++) {
// and store them in funcs
funcs[i] = function() {
// each should log its value.
console.log("My value: " + i);
};
}
for (var j = 0; j < 3; j++) {
// and now let's run each one to see
funcs[j]();
}
function myOuterFunc() {
var date = new Date();
function myInnerFunc() {
console.log("The current date is " + date)
if (true) {
// Whoops, we accidentally reused this variable name!
var date = "a string"
}
}
myInnerFunc()
}
function myOuterFunc() {
var date = new Date();
function myInnerFunc() {
var date = undefined;
console.log("The current date is " + date)
if (true) {
// Whoops, we accidentally reused this variable name!
date = "a string"
}
}
myInnerFunc()
}
ON CONDITION(OVERDRAFT) BEGIN; ... END; IF ACCOUNT_BALANCE < TOTAL WITHDRAWAL THEN SIGNAL CONDITION(OVERDRAFT);
String[] strings = new String[2];
Object[] objects = strings; // valid, String[] is Object[]
objects[0] = 12;
let mut x = "123".to_string();
let y = &mut x;
x.push_str("456");
println!("y = {}", y);
error[E0499]: cannot borrow `x` as mutable more than once at a time
data Exp = Num Int
| Add Exp Exp
| Sub Exp Exp
| Mul Exp Exp
| Div Exp Exp
eval :: (Num a, Integral a) => Exp -> a
eval e = case e of
Num x -> fromIntegral x
Add a b -> eval a + eval b
Sub a b -> eval a - eval b
Mul a b -> eval a * eval b
Div a b -> eval a `div` eval b