From 5a894c497a92bad65dc4072e546a35c2e144c50b Mon Sep 17 00:00:00 2001 From: minjaesong Date: Fri, 25 Dec 2020 14:59:21 +0900 Subject: [PATCH] basicdoc: some fixes --- assets/disk0/home/basic/sqrt2.bas | 10 ++++++++++ assets/disk0/tbas/doc/langguide.tex | 7 +++++-- 2 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 assets/disk0/home/basic/sqrt2.bas diff --git a/assets/disk0/home/basic/sqrt2.bas b/assets/disk0/home/basic/sqrt2.bas new file mode 100644 index 0000000..e15b75a --- /dev/null +++ b/assets/disk0/home/basic/sqrt2.bas @@ -0,0 +1,10 @@ +1 REM Calculates a square root using newtonian method +10 INPUT X +11 IF TYPEOF(X)=="num" THEN GOTO 20 +12 PRINT "Please type in a number, please"; +13 GOTO 10 +20 Y = 0.5 * X +30 Z = Y +40 Y = Y-(((Y^2)-X)/(2*Y)) +50 IF NOT(Z==Y) THEN GOTO 30 +100 PRINT "Square root of ";X;" is approximately ";Y diff --git a/assets/disk0/tbas/doc/langguide.tex b/assets/disk0/tbas/doc/langguide.tex index 712232e..2539c6c 100644 --- a/assets/disk0/tbas/doc/langguide.tex +++ b/assets/disk0/tbas/doc/langguide.tex @@ -23,13 +23,16 @@ Following program attempts to calculate a square root of the input value, showi 20 Y = 0.5 * X 30 Z = Y 40 Y = Y-(((Y^2)-X)/(2*Y)) -50 IF Z <> Y THEN GOTO 30 +50 IF NOT(Z==Y) THEN GOTO 30 : REM 'NOT(Z==Y)' can be rewritten to 'Z<>Y' 100 PRINT "Square root of ";X;" is approximately ";Y \end{lstlisting} -Here, \code{GOTO} in line 50 to perform a loop, which keep loops until \code{Z} and \code{Y} becomes equal. This is a newtonian method of approximating a square root. +Here, \code{GOTO} in line 50 is used to perform a loop, which keeps looping until \code{Z} and \code{Y} becomes equal. This is a newtonian method of approximating a square root. \section[When GOTO Is Bad]{Severe Acute Spaghettification Syndrome} + + + \section[Subroutine with GOSUB]{GOSUB to the rescue!} \section[FOR--NEXT Loop]{FOR ever loop NEXT}